add_action in wordpress using OOP?

admin

Administrator
Staff member
I am learning about OOP, and I think I am getting the hang of it. My question is why the author of a wordpress boilerplate plugin wrote the add action function like this

Code:
add_action('admin_init', array(&$this, 'admin_init'));

According to the codex I understand the
Code:
add_action
hook, the paramaters to be passed are
Code:
$tag
"The name of the action to which $function_to_add is hooked", and the function that you want hooked
Code:
$function_to_add
.

Well I understand the functions in OOP are methods, and I can see why that may change the syntax, but that is just a vague representation, I want a clear answer why the author uses an array, then uses
Code:
&$this
. I understand why one would use
Code:
$this->property
but not so sure about
Code:
&$this
.

Is it just how you refer to the method? If so I still dont understand the array, why wouldnt it look something like
Code:
$this->admin_init
.

By the way the structure looks kind of like this

Code:
    class my_plugin_settings {

            public function __construct() {

                    // register actions
                    add_action('admin_init', array(&$this, 'admin_init'));

            } 

            public function admin_init() {

                    //Settings here
            }
    }