Change user roles in Wordpress

PHOTO EMBED

Fri May 12 2023 14:42:36 GMT+0000 (Coordinated Universal Time)

Saved by @fostira #php #wordpress

<?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);
    }
}
?>
content_copyCOPY

The available roles in WordPress are *administrator*, *editor*, *author*, *contributor*, and *subscriber*.
https://romanmiranda.com/wordpress-snippet-change-users-role-by-username/