Created
November 29, 2015 09:52
-
-
Save digamber89/d30473a517f5556d4c48 to your computer and use it in GitHub Desktop.
Singleton Class Unhook action and Filters
This file contains 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
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