問題描述
我想能夠授予我的編輯權力來改變選單,這可以做到嗎?
外觀選項卡根本看起來不是一個選項,我可以這樣做嗎?
最佳解決方案
新增到您的主題的 functions.php:
// add editor the privilege to edit theme
// get the the role object
$role_object = get_role( 'editor' );
// add $cap capability to this role object
$role_object->add_cap( 'edit_theme_options' );
次佳解決方案
如果您希望使用者能夠更改導航選單,而不是其他外觀下的選項:使用此選項
// Do this only once. Can go anywhere inside your functions.php file
$role_object = get_role( 'editor' );
$role_object->add_cap( 'edit_theme_options' );
重新整理您的管理面板後,您可以註釋掉整個程式碼,因為上述程式碼將對資料庫進行持久更改。
您現在可以看到所有的編輯器可見的選項。您可以隱藏其他選項,如:
function hide_menu() {
remove_submenu_page( 'themes.php', 'themes.php' ); // hide the theme selection submenu
remove_submenu_page( 'themes.php', 'widgets.php' ); // hide the widgets 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', 'hide_menu');
hide_menu()功能中的最後 3 行是我主題的主題。您可以在管理面板中點選要隱藏的子選單找到第二個引數。您的網址將如下所示:example.com/wp-admin/themes.php?page=yiw_panel
所以在這個例子中,remove_submenu_page()函式的第二個引數是 yiw_panel
第三種解決方案
在 WordPress 3.8 中,這將比現在接受的答案更好。
/**
* @var $roleObject WP_Role
*/
$roleObject = get_role( 'editor' );
if (!$roleObject->has_cap( 'edit_theme_options' ) ) {
$roleObject->add_cap( 'edit_theme_options' );
}
第四種方案
當我看管理選單結構時,似乎 nav-menus.php 連結與能力 edit_theme_options 有關。您可以修改編輯器角色以包含此功能嗎?這也是 give them the option to edit widgets,我不知道這是否是一個問題?所有的選單 Ajax 的東西都受到這種功能的限制,所以只需更改管理選單功能,編輯選單可能會不起作用。
參考文獻
注:本文內容整合自 Google/Baidu/Bing 輔助翻譯的英文資料結果。如果您對結果不滿意,可以加入我們改善翻譯效果:薇曉朵技術論壇。