admin管理员组文章数量:1122826
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
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:
Share Improve this question edited Sep 26, 2018 at 13:12 T.Todua 5,8509 gold badges51 silver badges79 bronze badges asked Jan 12, 2014 at 12:29 EHermanEHerman 9992 gold badges16 silver badges33 bronze badges 2 |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
2 Answers
Reset to default 0It 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) );
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.
本文标签: create submenu pageerror function not found or invalid function name
版权声明:本文标题:create submenu page - error function not found or invalid function name 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736290557a1928538.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
custom_plugin_submenu_page_callback
? – s_ha_dum Commented Jan 12, 2014 at 14:57