Skip to content

Instantly share code, notes, and snippets.

@Otto42
Created July 24, 2019 19:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Otto42/9b4d351895a55e4dc2c953fa0f040eab to your computer and use it in GitHub Desktop.
Save Otto42/9b4d351895a55e4dc2c953fa0f040eab to your computer and use it in GitHub Desktop.
<?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