在删除带有长URL字符串的Wordpress子菜单时遇到麻烦


Trouble removing Wordpress submenus with long URL strings

我正在运行Wordpress multisite 4.3,我正试图从我的网站编辑的外观菜单中删除一些子菜单。我已经成功地用下面的代码删除了"主题"、"小部件"、"菜单"answers"定制"的弹出式链接,通过创建一个新功能并关闭:

$cap = 'no_see_menus';
function edit_admin_menus() {
    global $submenu;
    if(!current_user_can($cap)){
    remove_submenu_page('themes.php','themes.php');
    remove_submenu_page('themes.php','widgets.php');
    remove_submenu_page('themes.php','nav-menus.php');
    remove_submenu_page('themes.php','customize.php?return=%2Fic%2Fwp-admin%2Findex.php' );
    }
}
add_action( 'admin_menu', 'edit_admin_menus' );

当我试图删除指向标题和背景定制的链接时,问题就出现了,这两者都有包含&号的字符串。但是,即使将字符串中的'&'替换为&,该函数也不会拾取它:

remove_submenu_page('themes.php','customize.php?return=%2Fic%2Fwp-admin%2Findex.php&autofocus%5Bcontrol%5D=header_image' );  
remove_submenu_page('themes.php','customize.php?return=%2Fic%2Fwp-admin%2Findex.php&autofocus%5Bcontrol%5D=background_image' );

所以我被困在这里。非常感谢大家的建议。

您可以使用css display:none。诀窍是使用浏览器开发工具来确定子菜单是否具有足够唯一的id/class。

我能够用我确信是一个超级模糊的方法完成我所需要的。我必须为菜单的一部分创建一个函数,另一个函数来摆脱自定义标题和自定义背景菜单。这就是它丑陋的一面。

// remove some menus and sub-menus for custom editor role
$cap = 'no_see_menus';
function edit_admin_menus() {
global $submenu;
    if(!current_user_can($cap)){
        remove_menu_page('tools.php'); // Remove the Tools menu
    remove_submenu_page('themes.php','themes.php');
        remove_submenu_page('themes.php','customize.php?return=%2Fic%2Fwp-admin%2Findex.php' );
        remove_submenu_page('themes.php','customize.php?return=%2Fic%2Fwp-admin%2Fwidgets.php');
        remove_submenu_page('themes.php','customize.php?return=%2Fic%2Fwp-admin%2Fnav-menus.php');
        }
}
add_action( 'admin_menu', 'edit_admin_menus' );
// remove custom backgound and custom header menus and sub-menus for editor role
$cap = 'no_see_menus';
function remove_twentyeleven_options(){
    if(!current_user_can($cap)){
            remove_custom_background();
            remove_custom_image_header();
        }
}
add_action( 'after_setup_theme','remove_twentyeleven_options', 100 );

如果有人有更优雅的方法来实现这一点,请务必在这里发布。谢谢你的建议。