What you need to do is the following:
function my_plugin_menu() { add_menu_page('My Plugin', 'My Plugin', 'manage_options', 'my-plugin', array(new MyClass, 'index')); add_submenu_page('my-plugin', 'Add New Thing', 'Add New', 'manage_options', 'my-plugin-add', array('MyClass', 'add')); }
Using array('MyClass', 'index') forces php to execute the method as static methed, but passing the actual object as the first argument will call the method through the object.
function my_plugin_menu() { $Class = new MyClass(); add_menu_page( 'My Plugin', 'My Plugin', 'manage_options', 'my-plugin', array($Class, 'index') ); }
Will also work if you want to reuse an object.
RobertPitt
source share