Reputation: 458
I just gave single-site administrators the right to add brand new users by adding the following code to my custom plugin that deals with user roles:
function mc_admin_users_caps( $caps, $cap, $user_id, $args ){
foreach( $caps as $key => $capability ){
if( $capability != 'do_not_allow' )
continue;
switch( $cap ) {
case 'edit_user':
case 'edit_users':
$caps[$key] = 'edit_users';
break;
case 'delete_user':
case 'delete_users':
$caps[$key] = 'delete_users';
break;
case 'create_users':
$caps[$key] = $cap;
break;
}
}
return $caps; }
add_filter( 'map_meta_cap', 'mc_admin_users_caps', 1, 4 );
remove_all_filters( 'enable_edit_any_user_configuration' );
add_filter( 'enable_edit_any_user_configuration', '__return_true');
Now, when my admin logs in, they can add new users the way I want them to, but I don't want to give them the option to add an existing user. I attached a screenshot to help you see what I'm talking about. Any idea of how I can keep the ability for admins to add new users, but not existing ones?
Upvotes: 1
Views: 1094
Reputation: 1191
I just came across the same issue. For future reference:
To hide the "Add Existing Users" form in Network Admin > Users, you can add a filter to your default site functions.php like so
add_filter('show_network_site_users_add_existing_form', false);
However, this won't remove the form from the individual sites. For this, you'll just need to hide the form with CSS as there's no filter available.
Add the following to your default site theme functions.php
add_action('admin_head', 'remove_existing_user_form');
function remove_existing_user_form() {
if (!is_super_admin()) {
echo '<style>
#add-existing-user,
#add-existing-user + p,
#adduser {
display: none;
}
</style>';
}
}
It's not ideal, but it hides the form for all users except super admins and is what I ended up doing.
Upvotes: 1