Let Site Admins Edit Their Own Site's Users
Allows site administrators to edit the profiles of users who belong to their site, which multisite normally reserves for super admins.
Opens WPIDE on
Code
if ( ! is_multisite() ) {
return;
}
add_filter( 'map_meta_cap', function ( $caps, $cap, $user_id, $args ) {
if ( 'edit_user' !== $cap || empty( $args[0] ) || is_super_admin( $user_id ) ) {
return $caps;
}
$target = (int) $args[0];
$blog = get_current_blog_id();
if ( $target === (int) $user_id || is_super_admin( $target ) || ! user_can( $user_id, 'promote_users' ) ) {
return $caps;
}
if ( is_user_member_of_blog( $target, $blog ) && 1 === count( get_blogs_of_user( $target ) ) ) {
return array( 'edit_users' );
}
return $caps;
}, 10, 4 );
Notes
Site admins can never edit super admins or users who belong to other sites as well, because profile changes are network-wide.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.