remove_action on a method: Why didn't this work?
-
I hope this is the right place to post this – if not, please just simply direct me to the right place!
I recently came across a plugin that, among other things, added a meta entry to the header. I needed to remove this action. The add_action entry looked like this:
add_action( 'wp_head', array( &$this, 'addMetaData' ) );
“this” is in relation to the class, called Vc_Base.
My initial reaction was to add the following to my functions.php:
function removeAddMetaData() { $vc = new Vc_Base(); remove_action('wp_head', array(&$vc, 'addMetaData'),10000); } add_action('init', 'removeAddMetaData', 10000);
This did not work. I also tried changing 10000 to other values.
What DID end up working was this:
function removeAddMetaData() { remove_action('wp_head', array(visual_composer(), 'addMetaData')); } add_action('init', 'removeAddMetaData');
I tracked down visual_composer() and it only has one line:
return vc_manager()->vc();
I tracked down vc_manager()->vc() and, among a few other things, it contains these lines:
$vc = new Vc_Base(); $this->factory['vc'] = $vc; return $this->factory['vc'];
So, if that’s just doing what I did (in a round-about way), why didn’t my initial idea work? I’d really appreciate some feedback since I feel I’ll understand WordPress/PHP a whole lot more if I can understand this!
Thanks in advance.
- The topic ‘remove_action on a method: Why didn't this work?’ is closed to new replies.