How to change a user’s role?


I have custom roles in my setup and I want to be able to automatically change a user’s role thru a function. Say user A has a SUBSCRIBER role, how do I change it to EDITOR? When adding a role we just:

add_role( $role_name , $role_display_name , array( 'read' =>  true,
                                                   'edit_posts' => false,
                                                   'delete_posts' => false, ));

How about changing a role? Is there something like:

change_role($old_role, $new_role);

I think this one will do:

$wp_user_object = new WP_User($current_user->ID);
Joann 2 months 0 Answers 12 views 0

Leave an answer