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!

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

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度