Last active
June 26, 2019 13:31
-
-
Save mtruitt/875a8ebdeb601ea736c61892fb1b1696 to your computer and use it in GitHub Desktop.
Allow WordPress editor to access widgets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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'); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This works with WP 4.0+