Skip to content

Instantly share code, notes, and snippets.

@szepeviktor
Last active May 14, 2016 18:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save szepeviktor/dccf4130f23041c5db89522732c28256 to your computer and use it in GitHub Desktop.
Save szepeviktor/dccf4130f23041c5db89522732c28256 to your computer and use it in GitHub Desktop.
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