問題描述

我想給編輯器角色訪問編輯邊欄和它的內容。我在那裏有一個文本小工具,為了編輯這個文本小工具,用户需要一個管理員 – 這很糟糕。如何授予編輯角色的權限,讓他可以編輯邊欄?

最佳解決方案

edit_theme_options 功能應允許用户按照本頁所述編輯側邊欄:http://codex.wordpress.org/Appearance_Widgets_SubPanel

代碼添加到 functions.php

   $role = get_role('editor');
   $role->add_cap('edit_theme_options');

編輯:

這應該可以防止編輯器訪問主題或菜單

function custom_admin_menu() {

    $user = new WP_User(get_current_user_id());
    if (!empty( $user->roles) && is_array($user->roles)) {
        foreach ($user->roles as $role)
            $role = $role;
    }

    if($role == "editor") {
       remove_submenu_page( 'themes.php', 'themes.php' );
       remove_submenu_page( 'themes.php', 'nav-menus.php' );
    }
}

add_action('admin_menu', 'custom_admin_menu');

我沒有機會測試這個,但它只是從他們仍然可以通過直接輸入 URL 訪問它們的菜單中刪除它們。

參考文獻

注:本文內容整合自 Google/Baidu/Bing 輔助翻譯的英文資料結果。如果您對結果不滿意,可以加入我們改善翻譯效果:薇曉朵技術論壇。