Skip to content

Instantly share code, notes, and snippets.

@mtruitt
Last active June 26, 2019 13:31
Show Gist options
  • Select an option

  • Save mtruitt/875a8ebdeb601ea736c61892fb1b1696 to your computer and use it in GitHub Desktop.

Select an option

Save mtruitt/875a8ebdeb601ea736c61892fb1b1696 to your computer and use it in GitHub Desktop.
Allow WordPress editor to access widgets
<?php
// Elevate caps since theme options are required to access widgets
$role = get_role('shop_manager');
$role->add_cap('edit_theme_options');
// Allow Editor widget access but remove themes, menu options and customizer.
function custom_admin_menu() {
$user = new WP_User(get_current_user_id());
if (!empty( $user->roles) && is_array($user->roles)) {
foreach ($user->roles as $role)
$role = $role;
}
if($role == "editor") {
global $submenu;
// Loop through to get the index of customizer. This makes sure its removed even if a plugin or something else changed it.
if ( isset( $submenu[ 'themes.php' ] ) ) {
foreach ( $submenu[ 'themes.php' ] as $index => $menu_item ) {
if ( in_array( 'customize', $menu_item ) ) {
unset( $submenu[ 'themes.php' ][ $index ] );
}
}
}
remove_submenu_page( 'themes.php', 'themes.php' );
remove_submenu_page( 'themes.php', 'nav-menus.php' );
}
}
add_action('admin_menu', 'custom_admin_menu');
@mtruitt
Copy link
Author

mtruitt commented Jun 26, 2019

This works with WP 4.0+

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment