im trying to modify the Wordpress capability 'edit_users' for my plugin. In my case some User Roles should have the ability to modify some other Users with an specific Role BUT not every other Users.
So I just add the capability 'edit_users' to my custom Role 'Primary Trainer'. Now he can edit every User. I can use the 'edit_user' cap to check every shown Users.
Then i filtered this capability by:
add_filter( 'map_meta_cap',array($this,'sa_classbook_map_meta_cap'),10,4);
function sa_classbook_map_meta_cap( $caps, $cap, $user_id, $args ) {
switch( $cap ){
//Some Roles can only edit some Profiles
//Primary Trainer and Secondary Trainers are allowed to change Data of Participants but they cant change other Trainers Data
case 'edit_user':
if( isset($args[0]) && $args[0] == $user_id )
break;
elseif( !isset($args[0]) )
$caps[] = 'do_not_allow';
$other = new WP_User( absint($args[0]) );
//If the Current User is not the Admin
if(!current_user_can('administrator')){
//If the shown Profile is an Primary Trainer, an Secondary Trainer or the Admin it should'nt be editable
if(!in_array( 'sa_classbook_participant', (array) $other->roles)){
$caps[] = 'do_not_allow';
}
}
break;
default:
break;
}
return $caps;
}
For the Backend it works perfectly see picture:
But now comes Buddy Press:
Buddypress give the ability to edit users information in Frontend. But the thing is my filter wont be called. There seems only the ability to give the capability to edit every user or none.
Heres a Picture so you see what i mean:
Do you have an idea ? Or maybe a better solution ?