Instantly share code, notes, and snippets.

Embed
What would you like to do?
Menus edit for Editors in WordPress
<?php
/*
Plugin Name: Menu edit for Editors
Version: 0.1.0
*/
// Before the administration menu loads
add_action( '_admin_menu', 'o1_menu_edit_for_editors', 0 );
function o1_menu_edit_for_editors() {
$current_user = wp_get_current_user();
// This is not an editor
if ( ! in_array( 'editor', $current_user->roles ) ) {
return;
}
// Add Menus as a top-level menu page
add_menu_page( __( 'Menus' ), __( 'Menus' ), 'edit_pages', 'nav-menus.php', '', 'dashicons-admin-appearance', 60 );
// Remove Appearance menu (gets added because of "edit_theme_options")
remove_menu_page( 'themes.php' );
global $pagenow;
// We are on the Menus page
if ( 'nav-menus.php' === $pagenow ) {
// Elevate editors from _admin_menu on
add_filter( 'user_has_cap', 'o1_add_edit_theme_options_to_editor' );
// Hide Customizer
$style = '.hide-if-no-customize { display: none; }';
wp_add_inline_style( 'wp-admin', $style );
}
}
function o1_add_edit_theme_options_to_editor( $allcaps ) {
$allcaps['edit_theme_options'] = true;
return $allcaps;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment