0

I have created a plugin with a top level page. I created a sub menu underneath that. When I run the plugin on my site everything works. But when I test it on a separate site I get an error and I'm not sure why.

This is the the code that is in question and the error that is getting thrown. I can't for the life of me figure out what the error is from.

function custom_plugin_add_menu_page(){

     add_menu_page( 'My Custom Plugin', 
                         'My Custom Plugin', 
                         'manage_options', 
                         'top_level_parent_page', 
                         'top_level_parent_page',
                         plugins_url( '/my-custom-plugin/includes/images/menu-icon.png' )
                         );                           

     add_submenu_page( 
        'top_level_parent_page', 
        'Custom Submenu Page', 
        'Custom Submenu Page',
        'manage_options', 
        'custom_plugin_submenu_page', 
        'custom_plugin_submenu_page_callback' 
    );                  
}
add_action('admin_menu', 'custom_plugin_add_menu_page');

and the error:

Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'custom_plugin_submenu_page_callback' not found or invalid function name in D:\xampp\htdocs\localtestsite\wp-includes\plugin.php on line 429

  • Where is custom_plugin_submenu_page_callback? – s_ha_dum Jan 12 '14 at 14:57
  • Directly below it the add_action call. I've seen this issue when the function no longer exists, but I can see that it exists. It seems to throw this error on localhost only. Not on a live site. It's strange – EHerman Jan 12 '14 at 19:05
0

It seems if you use classes you have to use array($this, $function)); in the function element as shown below.

add_submenu_page( $mainmenu_slug, $submenu_title, $submenu_label, $capability, $submenu_slug , array($this, $submenu_function) );   
  • No. It's used only when used in Class objects (which is $this), but not is plain codes like that. – T.Todua Sep 26 '18 at 13:13
0

problem 1

You have to declare the function custom_plugin_submenu_page_callback you are passing there

function custom_plugin_submenu_page_callback()
{ ?>
   hellooooo
<?php
}

obviously you have it on one site (maybe in functions.php) and you dont' have it on another site (or just the error's are turned off there).

problem 2

You have incorrect argument in add_menu_page - the 6th one should be the function name, not the icon name. You dont' get error on another site, because ERRORS are turned off there probably.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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