Created
July 24, 2019 19:21
-
-
Save Otto42/9b4d351895a55e4dc2c953fa0f040eab to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Testing | |
*/ | |
class Demo { | |
function do_a_thing() { | |
echo '<!-- demo -->'; | |
} | |
} | |
$instance = new Demo(); | |
add_action( 'wp_head', array( $instance, 'do_a_thing' ) ); | |
// problem: without access to $instance, removing this hook is hard | |
// solution: | |
add_action( 'plugins_loaded', 'remove_it' ); | |
function remove_it() { | |
global $wp_filter; | |
foreach( $wp_filter['wp_head']->callbacks as $priorities ) { | |
foreach ( $priorities as $name=>$action ) { | |
if ( | |
isset( $action['function'] ) | |
&& is_array( $action['function'] ) | |
&& isset( $action['function'][0] ) | |
&& is_object( $action['function'][0] ) | |
&& is_a ( $action['function'][0], 'Demo' ) | |
&& $action['function'][1] === 'do_a_thing' | |
) { | |
remove_action( 'wp_head', $name ); | |
} | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment