Chris
Chris

Reputation: 1

Remove action in an existing plugin class via another plugin

I am trying to remove an action within an existing WooThemes Sensei Class

global $woothemes_sensei; remove_action( 'sensei_single_course_modules_before', array( $woothemes_sensei->modules, 'course_modules_title' ),20 ); remove_action( 'sensei_single_course_modules_content', array( $woothemes_sensei->modules, 'course_module_content' ),30 );

I am not sure what I am doing wrong? I think I am calling the correct class with the global variable. And the labels are correct? I've tried various priorities.

Thank you!

Upvotes: 0

Views: 938

Answers (1)

helgatheviking
helgatheviking

Reputation: 26319

  1. You must wrap the remove functions in a function and attach it to a hook, before the action in question has been run.
  2. $this has no context here. it only has context inside a class
  3. remove_action must have the exact same priority as the add_action that you are trying to remove
  4. The course-modules.php template says exactly how the course_modules_title action is being added
/**
 * Hook runs inside single-course/course-modules.php
 *
 * It runs before the modules are shown. This hook fires on the single course page,but only if the course has modules.
 *
 * @since 1.8.0
 *
 * @hooked Sensei()->modules->course_modules_title - 20
 */
do_action('sensei_single_course_modules_before');

Sensei does not appear to be using a global and the modules class is accessed via Sensei()->modules as hinted at in the template. Therefore something like the following should remove your actions:

function so_31590319_remove_sensei_actions(){
    remove_action('sensei_single_course_modules_before',array( Sensei()->modules,'course_modules_title' ), 20);
    remove_action('sensei_single_course_modules_content', array( Sensei()->modules,'course_module_content' ), 20);
}
add_action( 'sensei_single_course_modules_before', 'so_31590319_remove_sensei_actions', 10 );

Upvotes: 1

Related Questions