我稍微修改了发布为答案的代码@Sally CJ 要处理多个案例,请执行以下操作:
public function __construct()
{
require(\'pxMagAdminPlans.class.php\');
require(\'pxMagAdminPromo.class.php\');
$this->admPlanObj= new pxMagAdminPlans();
$this->admPromoObj= new pxMagAdminPromo();
add_action(\'admin_menu\', array($this, \'add_plan_admin_menu\'));
add_filter(\'add_menu_classes\', array($this, \'adjust_menu_classes\'));
add_filter(\'submenu_file\', array($this, \'adjust_submenu_file\'), 10, 2 );
}
public function add_plan_admin_menu()
{
add_menu_page(__(\'Dashboard\', \'textdomain\'), get_bloginfo(\'name\'), \'manage_options\', \'pxmag-menu\', array($this, \'pxmag_dash\'), \'dashicons-welcome-view-site\', 6);
add_submenu_page(\'pxmag-menu\', __(\'Subscription Plans\', \'textdomain\'), \'Plans\', \'manage_options\', \'pxmag-plans\', array($this->admPlanObj, \'plan_admin_menu_page\'));
add_submenu_page(\'pxmag-plans\', __(\'Add/edit Plans\', \'textdomain\'), \'Add/edit plans\', \'manage_options\', \'pxmag-plans-edit\', array($this->admPlanObj, \'plan_admin_menu_edit\'));
add_submenu_page(\'pxmag-menu\', __(\'Manage Promotions\', \'textdomain\'), \'Promotions\', \'manage_options\', \'pxmag-promotions\', array($this->admPromoObj, \'get_promotions\'));
add_submenu_page(\'pxmag-promotions\', __(\'Add/Edit\', \'textdomain\'), \'Add/Edit\', \'manage_options\', \'pxmag-promotions-edit\', array($this->admPromoObj, \'manage_promotions\'));
remove_submenu_page(\'pxmag-menu\',\'pxmag-menu\');
}
function adjust_submenu_file($submenu_file, $parent_file) {
global $plugin_page;
$retsub = $submenu_file;
if(\'pxmag-plans-edit\' === $plugin_page)
$retsub = \'pxmag-plans\';
elseif (\'pxmag-promotions-edit\' === $plugin_page)
$retsub = \'pxmag-promotions\';
return $retsub;
}
function adjust_menu_classes($menu)
{
global $plugin_page;
$retmenu = $menu;
if ((\'pxmag-promotions-edit\' == $plugin_page) || (\'pxmag-plans-edit\' == $plugin_page))
{
foreach ($menu as $i => $item)
{
if (\'pxmag-menu\' === $item[2])
{
$retmenu[$i][4] = add_cssclass(\'wp-has-current-submenu wp-menu-open\', $item[4]);
}
}
}
return $retmenu;
}