JoryHogeveen / view-admin-as

View the WordPress admin as a different role, switch between users, temporarily change your capabilities, set default screen settings for roles, manage your roles and capabilities.
https://wordpress.org/plugins/view-admin-as/
GNU General Public License v2.0
45 stars 4 forks source link

Customizing a role? #72

Closed paaljoachim closed 7 years ago

paaljoachim commented 7 years ago

Hey

I happen to bump into this repo and I am taking a look at your plugin. It would be nice rename roles and customize them. For instance creating a client/customer/owner role hiding the plugins sidebar tab. Hiding Appearance -> Editor etc.

JoryHogeveen commented 7 years ago

Hi @paaljoachim,

Renaming roles is already possible. The only other customization for a role is it's capabilities, which is also possible :-). WP has no other data attached to roles.

For instance creating a client/customer/owner role hiding the plugins sidebar tab. Hiding Appearance -> Editor etc.

The Appearance menu item is linked to the capability edit_theme_options by default but it's submenu items do not have their own capabilities in WordPress.

There are some plugins which allow you to fully customize the menu's in WP based on roles etc. or you can use some custom code.

Plugin: https://wordpress.org/plugins/admin-menu-editor/

In your specific case (disabling the editor for a role), please check https://codex.wordpress.org/remove_submenu_page and choose which items to remove. You can wrap the code in this:

add_action( 'admin_menu', 'custom_remove_menu_items', 999 );
function custom_remove_menu_items() {
    $user = wp_get_current_user();
    if ( in_array( 'YOUR_ROLE', $user->roles ) ) {
        // Remove the menu items. For example the widgets item:
        remove_submenu_page( 'themes.php', 'widgets.php' );
    }
}

For now a feature like this is out of scope for this plugin as it is not meant to "change" the WP admin permanently.

Regards, Jory

paaljoachim commented 7 years ago

Thanks for the feedback Jory!