Custom WordPress admin menu: How to make it editable for editors?

时间:2016-10-20 18:44:58

标签: javascript wordpress

I have added a custom menu to the sidebar in the admin panel in WordPress:

function custom_settings_add_menu() {
  add_menu_page( 'custom_settings', 'Custom Settings', 'read', 'custom_settings', 'custom_settings_page', null, 20);
}
add_action( 'admin_menu', 'custom_settings_add_menu' );

With read, I could make the menu visible for editors, but when they try to change the settings, WordPress tells them that they don't have the necessary permissions.

Does anybody know how I can let editors make edits to the settings?

1 个答案:

答案 0 :(得分:3)

I think the correct permission to be able to change it is edit_theme_options, so try adding it to your functions.php:

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

You will then have all the options under appearance visible to the editors. You can hide the other options like so:

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
  //etc...

add_action('admin_head', 'hide_menu');

If you want to make life easier for these kind of adjustments, use the User Role Editor Plugin.