php - Removing a (conditional) action from a wordpress woothemes plugin -


i want remove message block using functions.php. action wish remove:

    if( empty( $active_ids ) ){                         add_action( 'sensei_loop_course_inside_before',                      array( $this, 'active_no_course_message_output' ) );             } 

so figure had refer class before access it's function wish remove, did:

function remove_no_active_courses_message(){     //classname function want remove is:     //class sensei_shortcode_user_courses implements sensei_shortcode_interface       remove_action( 'sensei_loop_course_inside_before', array( 'sensei_shortcode_user_courses', 'active_no_course_message_output' ) );      remove_action( 'sensei_loop_course_inside_before', array( $sensei_shortcode_user_courses, 'active_no_course_message_output' ) );   } add_action('sensei_loop_course_inside_before', 'remove_no_active_courses_message');  

but neither of 2 worked, suggestions?

edit: source class: https://github.com/automattic/sensei/blob/master/includes/shortcodes/class-sensei-shortcode-user-courses.php

edit 2 (note: when try global class object, var dumps null on class maybe problem cant access it's global element? woothemes sensei object works fine , can print stuff that. not accessing function via class object instance) tried of suggested answers:

    function remove_no_active_courses_message(){         //classname function want remove is:         //class sensei_shortcode_user_courses implements sensei_shortcode_interface           global $sensei_shortcode_user_courses; //doesnt seem instantiate?         global $woothemes_sensei; //works fine , can acces it's objects here          //var_dump($sensei_shortcode_user_courses); //prints null         //var_dump($woothemes_sensei); //prints entire thingy succesfully          remove_action( 'sensei_loop_course_inside_before', array( $sensei_shortcode_user_courses, 'active_no_course_message_output' ), 99 );  }        add_action('wp_footer', 'remove_no_active_courses_message');     

try this. i have not tested it. should work.

if action has been added within class, example plugin, removing require accessing class variable.

function remove_my_class_action() {     global $my_class; // class name     remove_action( 'sensei_loop_course_inside_before', array( $my_class, 'active_no_course_message_output' ) ); } add_action( 'wp_head', 'remove_my_class_action' ); 

edit: try adding priority or changing hook if not work.

it worth noting may need prioritise removal of action hook occurs after action added. cannot remove action before has been added.

solution 1 : tweaking priority

function remove_my_class_action() {     global $my_class; // class name     remove_action( 'sensei_loop_course_inside_before', array( $my_class, 'active_no_course_message_output', 99 ) ); } add_action( 'wp_head', 'remove_my_class_action' ); 

solution 2 : using wp_footer

function remove_my_class_action() {     global $my_class; // class name     remove_action( 'sensei_loop_course_inside_before', array( $my_class, 'active_no_course_message_output', 99 ) ); } add_action( 'wp_footer', 'remove_my_class_action' ); 

Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -