2017-04-27 73 views
0

我正在研究一个名为PointFinder的WordPress安装。用户发布的项目会在某个预定义的时间段后被删除。我的目标是禁用此行为。我已经找到相应的代码行,并取消激活add_action挂钩,该挂钩触发schedule-config.php中的周期性调用功能pointfinder_clean_pending_orders(),该功能暂时可以正常工作。如何安全地删除子主题中的动作钩子?

add_action('pointfinder_schedule_hooks_hourly', 'pointfinder_clean_pending_orders'); // <--- commented out this line 

function pointfinder_clean_pending_orders() { 
    /* code that cleans-up ... */ 
} 

如何在我的孩子主题中实现停用?如果我简单地在我的孩子主题中添加一个remove_actionfunctions.php,那会起作用吗?我不确定首先会叫什么,add_actionschedule-config.php或我的remove_actionfunctions.php

我只能访问生产性服务器和没有测试环境,因此我对实验有点不情愿。

回答

1

试试这个:

add_action('init','remove_hourly_hook'); 
function remove_hourly_hook() { 
    remove_action('pointfinder_schedule_hooks_hourly', 'pointfinder_clean_pending_orders'); 
} 

这样做是什么WordPress的初始化后(不管的functions.php的顺序被调用),它将然后删除的操作。

现在,如果最初的add_action在自己的钩子中,您将需要确保您的钩子'init'被更改为事后发生。

+0

感谢您的回答!根据https://codex.wordpress.org/Function_Reference/remove_action,没有只有一个参数的'remove_action'方法签名。而且,我没有太多的实验空间,因为我只能访问高效的网页。不幸的是,没有可用的测试环境,因此我需要非常肯定它会起作用,否则我将通过定期删除算法来释放更多数据。 – salocinx

+0

修复了具有正确方法用法的答案。 –

+0

非常感谢你:)我会试试这个。 – salocinx