In my user registration, the user can them selves choose their role.
But I have not been able to hook this up with user registration.
I’m also not able to run my function from my plugin using add_action.
So what I do now, is to call my function on page load (Above the header – before <!DOCTYPE>).
Unfortunately the user have to reload the page to see the effect. I’m currently looking into how I can solve this problem, and change user role before anything else is loaded (that is role based).
Here is my function:
function changeUserRole()
{
global $current_user;
get_currentuserinfo();
$user_ID = $current_user->ID;
$user = new WP_User( $user_ID );
$roles = array(... list of roles...);
// Set new user role.
foreach($roles as $role => $name) {
if( $current_user->role == $name)
$user->set_role($role);
}
}
PS. hmm… reading your Q again, this might not be the answer you are looking for 🙂
Did you however find a solution for your problem?
Thanks for answering me. I’m also changing users’ roles and capabilities on the fly in a similar way as the one you are using. However, this did not quite sort out my problem.
I just wanted to add an action when an admin user changes any other user’s role through the core backend.
If you have an idea…
Thanks 🙂
The action set_user_role would accomplish what you seek. It is called in wp-includes/capabilities.php
Thanks, I’ll check on that.