How to programmatically add a user to a role?

You can do that like this :

$my_user = new WP_User( $user_id );
$my_user->set_role( "editor" );

Leave a Comment