8

I'm trying to remove an action that a plugin registers in a separate functions.php file, but the syntax is stumping me. The plugin (I can't copy/paste - commercial plugin) infers to the add_action like so:

class Plugin_Class{

  function add_actions(){
    add_action('tag', array(&$this, 'function_to_remove'), 10); 
  }

  function_to_remove(){
    global $wp;
    // Code here
  }
}

I'm mostly confused with &$this. I know that this refers to the instance of the class, but based off my research it should be removed like so:

Need help with remove_action()

I just don't know how to come up with the syntax for my situation. Why define the global variable? Would I need to do that in my case? I'm assuming the widget array comes from WP core code, but I'm confused on how I need to implement this in my case, which seems to be much simpler. Sorry if this stuff is remedial.

Thanks for any help in advance.

Community
  • 1
  • 1
Steve
  • 592
  • 9
  • 24
  • More reading: http://wordpress.org/support/topic/remove_action-problem-when-function-is-within-class – Steve Jan 19 '12 at 10:36
  • I'm confused where it says, "Say we have a global". So I need to find a global defined in the class? – Steve Jan 19 '12 at 10:37
  • 1
    I get now that the global needs to be set to the variable that was assigned when the class was instantiated. Trying that but not working. http://wordpress.stackexchange.com/questions/36013/remove-action-or-remove-filter-with-external-classes – Steve Jan 19 '12 at 10:42
  • 1
    After speaking with the plugin developer, this no longer needs to be done but I'm still very curious on the solution. – Steve Jan 19 '12 at 19:15

1 Answers1

1

The &$this creates a reference instead of a copy. That way when you access that variable later, you really access this object and not a copy.

http://www.php.net/manual/en/language.references.whatdo.php

See the paragraph about array "not exactly assigning by reference, but equivalent."

Alexis Wilke
  • 19,179
  • 10
  • 84
  • 156