Thank you Vladimir,
Sorry, I actually did use set_role I also tried a few other things and that was my last code I pasted.
But I still seem to be having an issue and its really eluding me…
First, I have checked URE and the roles I added. The name is Volunteer User and the ID is volunteer_user
URE
I also checked the database in the options table and usermeta table and the Role is s:14:”volunteer_user“;b:1;
When I use this code:
add_action( 'edit_user_profile_update', 'my_save_extra_profile_fields' );
function my_save_extra_profile_fields( $user_id ) {
//if ( current_user_can( 'edit_user', $user_id ) )
$user = new WP_User( $user_id );
$user->set_role('volunteer_user');
}
When I click the “Update User” button on the user-edit.php page it basically looks like nothing happens, the user is never added to the “Volunteer User” role as I expect it to.
So just out of curiosity I tried ‘contributor’ and still, nothing happened. At this point I thought the code was not working.
But the weird part is the if I replace the role ID with something that does NOT exist, for example this code:
add_action( 'edit_user_profile_update', 'my_save_extra_profile_fields' );
function my_save_extra_profile_fields( $user_id ) {
//if ( current_user_can( 'edit_user', $user_id ) )
$user = new WP_User( $user_id );
$user->set_role('FAKE ROLE');
}
and then I click the “Update User” button, it creates the new capability and assigns the user that capability
URE2
So I know the function is firing.
I have triple checked the spelling (all lower case)
I disabled ALL plugins
Everything I am reading says this is being done correctly.
I’m sitting here scratching my head at this point.
Kindest Regards