2017-08-03 72 views
0

(第一,對不起我的英文不好)WordPress的:Add_cap ||編輯菜單僅

我想知道如果有一個純PHP的方式,讓一個編輯器用戶編輯菜單。

此代碼允許編輯訪問外觀菜單,它工作正常。

// get the the role object 
$role_object = get_role('editor'); 

// add capability to this role object 
$role_object->add_cap('edit_theme_options'); 

但我不想讓他編輯的主題或部件。我知道有插件來管理這些功能,但我正在尋找一個簡單的PHP方式來做到這一點,任何想法?

在此先感謝!

回答

1

您對此有何看法?

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

add_action('admin_head', function() 
{ 
    // Check if the user === 'editor' 
    if (is_object(get_role('editor'))) { 
     remove_submenu_page('themes.php', 'themes.php'); 
     remove_submenu_page('themes.php', 'widgets.php'); 
    } 
}); 
+0

我不知道'remove_submenu_page'!確實幫助了很多人,這正是我所期待的,謝謝!我有點新的Wordpress :) –

+0

@AlexisWollseifen很高興它現在工作!不要忘記設置你的問題來解決。 – justkidding96