How to remove a WordPress action which uses the current object - $this?

后端 未结 3 1374
面向向阳花
面向向阳花 2021-02-06 14:42

I\'m familiar with remove_action when removing an action in WordPress.

To create the action: add_action( \'action_hook\', \'function_name\', 10, 3 );<

3条回答
  •  暖寄归人
    2021-02-06 15:04

    To extend on Rikesh answer: Sadly, using class name will not work. As it says on https://codex.wordpress.org/Function_Reference/remove_action

    If an action has been added from within a class, for example by a plugin, removing it will require accessing the class variable.

    This leaves only:

    global $my_class;
    remove_action( 'some_action_hook', array( $my_class, 'some_function' ) );
    

    Or in case of a singleton class like Jetpack to remove the 'show_development_mode_notice' hook (for example) like this:

    remove_action( 'jetpack_notices', array( Jetpack::init(), 'show_development_mode_notice' ) );
    

提交回复
热议问题