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 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化