Title: Users without a role
Last modified: September 1, 2016

---

# Users without a role

 *  [genghiskhano](https://wordpress.org/support/users/genghiskhano/)
 * (@genghiskhano)
 * [9 years, 10 months ago](https://wordpress.org/support/topic/users-without-a-role-1/)
 * Hello,
    I have about 8000 users without a role, is there a way to charge the 
   role of all my users without a role to subscriber automatically ? Thanks,

Viewing 1 replies (of 1 total)

 *  [cedcommerce](https://wordpress.org/support/users/cedcommerce/)
 * (@cedcommerce)
 * [9 years, 10 months ago](https://wordpress.org/support/topic/users-without-a-role-1/#post-7527677)
 * Hey genghiskhano,
 * First take a backup of your db. And then create a file just in the parallel of
   wp-content folder.
    And then paste the following code in your newly created file.
 *     ```
       <?php
       include_once 'wp-blog-header.php';
       $all_users = get_users();
   
       if ( !empty( $all_users ) ) {
        foreach ( $all_users as $user ) {
         if ( !empty( $user ) ) {
          if ( empty( $user->roles ) ) {
           $role = 'subscriber';
           $user_id = wp_update_user( array( 'ID' => $user->ID, 'role' => $role ) );
   
           if ( is_wp_error( $user_id ) ) {
            echo "There was an error for user id:".$user->ID." <br>";
           } else {
            echo 'Successfully updated user with role '.$role.', where user id is: '.$user->ID.'<br>';
           }
          }
         }
        }
       }
       ?>
       ```
   
 * Now run this file by [https://yoursite.com/created_file.php](https://yoursite.com/created_file.php)
   and wait for a while until the script is running.
    When completed, see if there
   no error like “There was an error for user id”. And then check your user now.
   Hope, this will do all good for you.

Viewing 1 replies (of 1 total)

The topic ‘Users without a role’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 2 participants
 * Last reply from: [cedcommerce](https://wordpress.org/support/users/cedcommerce/)
 * Last activity: [9 years, 10 months ago](https://wordpress.org/support/topic/users-without-a-role-1/#post-7527677)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
