php 隐藏WordPress中编辑器角色的菜单项

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 隐藏WordPress中编辑器角色的菜单项相关的知识,希望对你有一定的参考价值。

<?php

// add editor the privilege to edit theme
// comment out after reloading site
// get the the role object
$role_object = get_role( 'editor' );
// add $cap capability to this role object
$role_object->add_cap( 'edit_theme_options' );
// comment out above after reloading site

function xxx_hide_menu() {
    if (current_user_can('editor')) {
        remove_submenu_page( 'themes.php', 'themes.php' ); // hide the theme selection submenu
        remove_submenu_page( 'themes.php', 'widgets.php' ); // hide the widgets submenu
        remove_submenu_page( 'themes.php', 'customize.php?return=%2Fwp-admin%2Ftools.php' ); // hide the customizer submenu
        remove_submenu_page( 'themes.php', 'customize.php?return=%2Fwp-admin%2Ftools.php&#038;autofocus%5Bcontrol%5D=background_image' ); // hide the background submenu
        // these are theme-specific. Can have other names or simply not exist in your current theme.
        remove_submenu_page( 'themes.php', 'yiw_panel' );
        remove_submenu_page( 'themes.php', 'custom-header' );
        remove_submenu_page( 'themes.php', 'custom-background' );
    }
}

add_action('admin_head', 'xxx_hide_menu');

// source - https://wordpress.stackexchange.com/questions/4191/allow-editors-to-edit-menus

以上是关于php 隐藏WordPress中编辑器角色的菜单项的主要内容,如果未能解决你的问题,请参考以下文章

PHP 根据WordPress中的用户角色显示/隐藏内容

php 从WordPress管理区域的侧边菜单中隐藏本机类别和标签

php 从WordPress管理区域的侧边菜单中隐藏本机类别和标签

PHP Wordpress隐藏管理菜单+子菜单

php 从WordPress-Backen中删除菜单项

php 隐藏菜单链接 - WordPress管理员