$page_title = "PushBIZ.IN";
$menu_title = "PushBIZ.IN";
$capability = 'activate_plugins';
$menu_slug = "pushbiz";
$function = "PushBIZIN_first";
add_menu_page( __('Getting Started'), $menu_title, $capability, $menu_slug, array($this, $function), plugins_url( WPPUSH_APPNAME.'/assets/images/app20x20.png' ) );
add_submenu_page( $menu_slug, __('BIZ Message'), __('BIZ Message'), $capability, 'BIZMessage', array($this, 'BIZ_Message') );
add_submenu_page( $menu_slug, __('Business Analyst'), __('Business Analyst'), $capability, 'businessanalyst', array($this, 'business_analyst') );
add_submenu_page( $menu_slug, __('BIZ Interests'), __('BIZ Interests'), $capability, 'BIZinterests', array($this, 'BIZ_interests') );
Warning: call_user_func_array() expects parameter 1 to be a valid callback, first array member is not a valid class name or object in C:\wamp\www\wp\wp-includes\plugin.php on line 525
ADD menu and sub-menu in word-press admin panel -> try this
function jmenu_plugin_top_menu(){
add_menu_page('My Plugin', 'My Plugin', 'manage_options', __FILE__, 'jmenu_render_plugin_page', plugins_url('/img/icon.png',__DIR__));
add_submenu_page(__FILE__, 'Custom', 'Custom', 'manage_options', __FILE__.'/custom', 'jmenu_render_custom_page');
add_submenu_page(__FILE__, 'About', 'About', 'manage_options', __FILE__.'/about', 'jmenu_render_about_page');
}
function jmenu_render_plugin_page(){
?>
<div class='wrap'>
<h2>plugin page</h2>
</div>
<?php
}
function jmenu_render_custom_page(){
?>
<div class='wrap'>
<h2>my sub page</h2>
</div>
<?php
}
function jmenu_render_about_page(){
?>
<div class='wrap'>
<h2>About my plugin page</h2>
</div>
<?php
}
add_action('admin_menu','jmenu_plugin_top_menu');
it will add menu and sub-menu in admin panel.
You can also refer this links for adding menu and submenu in admin panel.
http://clivern.com/adding-menus-and-submenus-for-wordpress-plugins/
https://developer.wordpress.org/reference/functions/add_submenu_page/
为了维护方便,把下面的代码封装在插件里了,只要启用插件就可以实现在WordPress后台添加菜单,当然也可以把代码放在主题的functions.php函数里
<?php
/**
* Plugin Name: Add a Custom Menu
* Author: WPScale
* Description: This is a demo for <a href="#">Add a Custom Menu</a>
* Author URI: https://wpscale.cn
* Version:0.0.0
*/
/**
* Register a custom menu page.
*/
add_action( 'admin_menu', 'add_a_custom_menu' );
function add_a_custom_menu(){
add_menu_page(
__( '在浏览器Tab栏显示', 'textdomain' ),
'用户自定义主菜单',
'read',
'custompage',//在浏览器地址显示的别名
'custom_menu_page_content',//定义菜单内容的函数
plugins_url('testplugin/images/logo.jpg' ),5
);
add_submenu_page(
'custompage',
__('浏览器tab栏子菜单1', 'textdomain'),
'子菜单1',
'read',
'submenu1',
'custom_submenu_page_content',//定义菜单内容的函数
);
add_submenu_page(
'custompage',
__('浏览器tab栏子菜单2', 'textdomain'),
'子菜单2',
'read',
'submenu2',
'custom_submenu_page_content',//定义菜单内容的函数
);
}
/**
* Display a custom menu page
*/
function custom_menu_page_content(){
// esc_html_e( '用户自定义菜单内容区', 'textdomain' );
?>
<?php
}
function custom_submenu_page_content(){
esc_html_e( '子菜单内容区', 'textdomain' );
?>
<div>
<label for="">设置</label>
<select name="" id="">
<option value="1">1</option>
<option value="2">2</option>
</select>
</div>
<?php
}
?>