dsfhe34889789708 2016-08-01 14:46
浏览 55
已采纳

如何在插件文件中取消挂钩WordPress动作挂钩?

I am trying to unhook and modify an action from within my child themes functions.php file.

The WordPress plugin Sensei, adds this action in line 86 of this document.

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

The action references a function further down the page that is responsible for outputting a dynamic header element.

/**
 * 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>';
    }
}

My goal here is to change the html currently output as 'Modules' to something else.

I have tried to the following in my child themes functions.php file but neither seem to be working.

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);

The issue is, I do not know how to determine which initial parameter, to add to the array to call the correct class. Because I am accessing it externally I cannot use $this like it is being used in the core file.

  • 写回答

1条回答 默认 最新

  • dsbpaqt61965 2016-08-01 18:54
    关注

    In order to remove the action you have to find the instance of the class. This is an assumption since I don't have access to the source code of Sensei but big chance there is one since most WordPress plug-ins use this method.

    When you find the instance name you can load it using global $senseiInstance - replace this with the actual name of the variable.

    Then you can remove the action using for example this code:

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

    More information can be found in for example this article: https://www.sitepoint.com/digging-deeper-wordpress-hooks-filters.

    Hope this helps you out!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 请问各位,如何在Jetson nano主控板的Ubuntu系统中安装PyQt5
  • ¥15 MAC安装佳能LBP2900驱动的网盘提取码
  • ¥400 微信停车小程序谁懂的来
  • ¥15 ATAC测序到底用什么peak文件做Diffbind差异分析
  • ¥15 安装ubantu过程中第一个vfat 文件挂载失败
  • ¥20 GZ::CTF如何兼容一些靶机?
  • ¥15 etcd集群部署问题
  • ¥20 谁可以帮我一下问一下各位
  • ¥15 为何重叠加权后love图的SMD与svyCreateTableOne函数绘制基线表的不一致
  • ¥150 求 《小魔指》街机游戏机整合模拟软件