admin管理员组文章数量:1201993
I have a class like below.
namespace Inc\Admin;
class Admin
{
public function __construct()
{
add_action('admin_menu', [$this, 'admin_menu']);
}
public function admin_menu()
{
add_submenu_page('sports_info', 'Sports Information', 'Sports Information', 'manage_options', [$this,'sports_info_page'], [$this, 'html_page']);
}
public function html_page() {
//some code
}
public function sports_info_page() {
//some code
}
}
I am getting below errors.
Fatal error: Uncaught Error: Object of class Inc\Admin\Admin could not be converted to string
Error comes from [$this,'sports_info_page']
of add_submenu_page()
.
I have a class like below.
namespace Inc\Admin;
class Admin
{
public function __construct()
{
add_action('admin_menu', [$this, 'admin_menu']);
}
public function admin_menu()
{
add_submenu_page('sports_info', 'Sports Information', 'Sports Information', 'manage_options', [$this,'sports_info_page'], [$this, 'html_page']);
}
public function html_page() {
//some code
}
public function sports_info_page() {
//some code
}
}
I am getting below errors.
Fatal error: Uncaught Error: Object of class Inc\Admin\Admin could not be converted to string
Error comes from [$this,'sports_info_page']
of add_submenu_page()
.
1 Answer
Reset to default 1You're getting that error because the 5th parameter for add_submenu_page()
should be a string which is the menu slug and yet you supplied a callback ([$this,'sports_info_page']
). So be sure to use a valid slug like so and the error will be gone:
add_submenu_page(
'sports_info', // parent slug
'Sports Information', // page title
'Sports Information', // menu title
'manage_options', // capability
'your-menu-slug', // menu slug
[$this,'sports_info_page'] // callback
);
本文标签: pluginsUse current class method inside addsubmenupage()
版权声明:本文标题:plugins - Use current class method inside add_submenu_page() 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738596626a2101821.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
sports_info
?) is added, but make sure that you used the correct parent slug. Or did you mean to add a top-level menu instead, e.g. usingadd_menu_page()
? – Sally CJ Commented May 9, 2022 at 9:02