无法删除带有长URL字符串的Wordpress子菜单

时间:2015-08-27 15:52:06

标签: php wordpress

我正在运行Wordpress多站点4.3,并且我试图从我的站点编辑器的“外观”菜单中删除一些子菜单。我已经成功删除了与主题的飞出链接,' '窗口小部件,' '菜单'并定制'使用下面的代码,通过创建一个新功能并键入:

$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' );

所以我被困在这里。我非常感谢任何建议。

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

我能够用我确定的超级方法来完成我所需要的东西。我不得不为部分菜单创建一个函数,另一个函数去除自定义标题和自定义背景菜单。这就是它的丑陋。

// 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 );

如果有人有更优雅的方式来实现这一目标,请务必在此处发布。感谢您的建议。