<?php $usernames = ['username1', 'username2', ...]; // An array of the usernames of the users you want to change the role for $new_role = 'new_role'; // The new role you want to assign to the users foreach ($usernames as $username) { $user = get_user_by('login', $username); if (!empty($user)) { $user->set_role($new_role); } } ?>