WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I used to develop in functional design so far and I am now learning OOP. I stumbled upon following problem.

Sometimes in OOP a function needs to send and argument as an array.

Example. I want to add an admin page for a plugin in Wordpress.

In functional design the function looks like this:

function myclass_plugin_admin_add_page() {
    add_options_page('MyClassPlugin Page', 'MyClassPlugin Menu', 'manage_options', 'do_myclass', 'myclass_plugin_options_page');

In OOP the last argument has to look like this:

function myclass_plugin_admin_add_page() {
    add_options_page('MyClassPlugin Page', 'MyClassPlugin Menu', 'manage_options', 'do_myclass', array($this, 'myclass_plugin_options_page'));

How the heck will I ever know which argument I have to change to an array when writing the same function in OOP???

share|improve this question

Replace this line:

add_options_page('MyClassPlugin Page', 'MyClassPlugin Menu', 'manage_options', 'do_myclass', 'myclass_plugin_options_page');


add_options_page('MyClassPlugin Page', 'MyClassPlugin Menu', 'manage_options', 'do_myclass', array( $this, 'myclass_plugin_options_page' ) );

i.e. you need to call the class method with

array( $this, 'myclass_plugin_options_page' )

instead of

share|improve this answer
Thanks birgire! I just found out your answer myself and rephrased my question. How can I find out which function's arguments I have to pass as an array when switching to OOP? – AleV Jul 24 '13 at 12:13
ok I see you changed the question, maybe you should add the new part after the original question to avoid confusion ;-) Usually it's done to the class methods. Check out the tutorials on hardcorewp.com (for example), they are really helpful, like this one: hardcorewp.com/2012/… – birgire Jul 24 '13 at 12:20

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.