I thought I was making headway in my WordPress Development education until I ran across the Boilerplate for WordPress plugins and it uses a class object. I’m fine with that and understand those concepts and I am a .Net developer. But, for some reason, I cannot get any callback to function properly. All I want at this point is an admin menu and when you click on that menu item, it display something like “PLEASE HELP ME!!!”. Check out what I have below and can anyone please explain what I have wrong?
class school_manager {
function __construct() {
add_action( 'init', array( $this, 'init' ) );
}
public function init(){
add_action('admin_menu', array(&$this, 'add_admin_menu'));
}
public function add_admin_menu(){
add_menu_page( 'School Manager Settings', 'School Manager', 'administrator', 'school-manager-settings', 'show_admin_settings_page', null );
}
public function show_admin_settings_page(){
echo '<p>This is a test for the admin settings page. Please work!</p>';
}
}
My new menu item does appear (as it did when I was not using a class object in my plugin architecture. But, when I click on the menu item, I get the following error:
Warning: call_user_func_array() [function.call-user-func-array]: First
argument is expected to be a valid callback,
‘school_manager::create_admin_page’ was given in
H:roothomexxxxxwp-includesplugin.php on line 406
I am trying to create a plugin that has not only an admin menu and submenu items, but also want to utilize the Settings API by trying to follow this series. So, this is one of the crucial points to get something as simple as a menu item to function before I can continue.
The callback you have given in
add_menu_page()
is a static function, not a class method. It should be:And please don’t use
&$this
anymore, that’s PHP 4. 🙂My demo plugin T5 Admin Menu Demo might help understanding how that works.