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.
Note:
Mobile screens are not wide enough to show all adminbar icons so this could cause the item to alread on a second line when there are more plugins active.
WP should fix this in core.
Currently users that have the view_admin_as capability can also switch roles ("lower" roles) and capabilities (only their own capabilities can be selected).
I think these options are not needed for these type of users and maybe it should be removed since they likely won't be used.
The only function that I think could be handy in this case is user switching since it allows some support-like ability for higher ranking site users.
Currently there is a meta query running for every user when using the get_users() function.
This is fine for networks with a few users, but for large networks this can take a lot of time.
/** * $WPDB_ stands for the db prefix*/SELECT users.*, usermeta.meta_valueAS roles
FROM {$wpdb->users} users
INNER JOIN {$wpdb->usermeta} usermeta
ONusers.ID=usermeta.user_idWHEREusermeta.meta_key='{$wpdb->get_blog_prefix()}capabilities'ORDER BYusers.display_name
Optional improvements:
Using MAXCASE we can select more meta values if needed (check compat with MySQL 5.0, WP minimum)
/** * $WPDB_ stands for the db prefix*/SELECT users.*,
MAX(CASE WHEN usermeta.meta_key='{$wpdb->get_blog_prefix()}capabilities' THEN usermeta.meta_value ELSE NULL END) roles
FROM {$wpdb->users} users
INNER JOIN {$wpdb->usermeta} usermeta
ONusers.ID=usermeta.user_idGROUP BYusers.IDHAVING roles is not null/* $WPDB_PREFIX_capabilities meta value required, otherwise the user isn't a member of the current blog */ORDER BYusers.display_name
When other plugins use the user_has_cap filter, VAA overwrites this in a view.
It might be more logical to put our filters at as first, so all other plugin's can still do their magic.
This way the filter get's actually run as if it's a different role instead of a being overwritten by view admin as.
Extra:
Maybe it's good to use the user_has_cap filter in our map_meta_cap filter as well to ensure we get the proper capability modifications from other plugins.
The plugin runs fine with a lot of users but when other plugins hook into the user capabilities with queries the load time can still be affected heavily.
The options/features below should fix this:
Limit user query to a max of 100 results. This can be changed with the filter: view_admin_as_user_query_limit
When there are more users than the limit (default: 100), switch to AJAX search instead of loading all users.
Option to disable the user view type UI. It is then still possible to switch from the user lists page. #84
Log:
Run tests on a blog with a LOT of users
100+ works good! Hardly noticeable
500+ works good! Hardly noticeable
5000+ @planetahuevo reported errors using membership plugins.
Check if there is something to do to fix reloading and capabilities. Currentlt when you switch to a different view in the customizer is reloads the regular page (non-customizer) in the iFrame or it shows a not-allowed page.
When a role or capability view is selected the current user is still the same. So if any plugins only validate a is_super_admin() check instead of current_user_can() these checks would return true.
Not 100% sure but I'd say that when a view is selected, is_super_admin() should return false.
Maybe make it optional??
Only disable on non-network admin pages
Tests:
This effectively disables functions grant_super_admin() and revoke_super_admin() since it sets/changes the $super_admins global variable. So when you switch to another super admin (as a superior admin) adding other users to the super admin list should not work.
When defaults are applied to roles and these roles are removed the defaults still exists.
I'd like to keep it this way so the user can add the roles again and keep the defaults.
But, I'll add them to the clear roles list so the user can remove them.