Skip to content

Instantly share code, notes, and snippets.

@digamber89
Created November 29, 2015 09:52
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 digamber89/d30473a517f5556d4c48 to your computer and use it in GitHub Desktop.
Save digamber89/d30473a517f5556d4c48 to your computer and use it in GitHub Desktop.
Singleton Class Unhook action and Filters
class myClass{
protected static $instance = null;
public function __construct(){
add_filter('the_content', array($this, 'add_text'));
}
public static function get_instance(){
// If the single instance hasn't been set, set it now.
if ( is_null( self::$instance ) ) {
self::$instance = new self();
}
return self::$instance;
}
public function add_text($content){
return 'digthis 123'.$content;
}
}
add_action('init', array('myClass','get_instance'), 10);
add_action('init', function(){
$pinstance = myClass::get_instance();
remove_filter( 'the_content', array($pinstance,'add_text'), 10 );
}, 20);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment