2016-08-01 134 views
0

我想从我的子主题functions.php文件中解除并修改一个动作。如何在插件文件中解除WordPress动作钩子?

WordPress插件Sensei在本文档的第86行添加了此操作。

https://github.com/Automattic/sensei/blob/master/includes/class-sensei-modules.php#L86

动作进一步引用的功能下降,负责用于输出动态头部元素的页面。

/** 
* Show the title modules on the single course template. 
* 
* Function is hooked into sensei_single_course_modules_before. 
* 
* @since 1.8.0 
* @return void 
*/ 

public function course_modules_title() { 
    if(sensei_module_has_lessons()){ 
     echo '<header><h2>' . __('Modules', 'woothemes-sensei') . '</h2></header>'; 
    } 
} 

我的目标是将当前输出为'Modules'的html改为别的。

我已经尝试了以下在我的子主题functions.php文件,但似乎都没有工作。

remove_action('sensei_single_course_modules_before', array('Sensei_Core_Modules', 'course_modules_title'), 20); 

remove_action('sensei_single_course_modules_before', array('Sensei()->Sensei_Core_Modules', 'course_modules_title'), 20); 

的问题是,我不知道如何确定初始参数,要添加到数组来调用正确的类。因为我正在外部访问它,所以我不能使用$this,因为它正在核心文件中使用。

回答

0

为了删除操作,你必须找到类的实例。这是一个假设,因为我无法访问Sensei的源代码,但由于大多数WordPress插件使用此方法,因此存在很大的机会。

当您找到实例名称时,您可以使用global $senseiInstance加载它 - 将其替换为变量的实际名称。

然后你就可以使用例如该代码中删除的操作:

remove_action('sensei_single_course_modules_before', array($senseiInstance, 'course_modules_title'), 20);

的更多信息可参见例如这篇文章:https://www.sitepoint.com/digging-deeper-wordpress-hooks-filters

希望这可以帮助你!