Title: User Role Plugin
Last modified: June 22, 2020

---

# User Role Plugin

 *  Resolved [pits24](https://wordpress.org/support/users/pits24/)
 * (@pits24)
 * [5 years, 11 months ago](https://wordpress.org/support/topic/user-role-plugin-3/)
 * Hi,
    I am looking for a plugin that deactivates (not delete) a certain role 30
   days after it registers. Note that I currently have a separate registration page
   for this type of user. Any help is appreciated!

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [corrinarusso](https://wordpress.org/support/users/corrinarusso/)
 * (@corrinarusso)
 * [5 years, 11 months ago](https://wordpress.org/support/topic/user-role-plugin-3/#post-13027198)
 * You could write your own plugin, or you could just write a php script.
    I think
   it would be best if you create a cron that runs daily, or twice a day. WordPress
   already has the method to remove the role : [https://developer.wordpress.org/reference/classes/wp_user/remove_role/](https://developer.wordpress.org/reference/classes/wp_user/remove_role/)
 * Basically, the script would :
    – loop through the users – get all users that 
   are registered today minus 30 days – remove the role from those users
 *     ```
       $users = get_users( fields' => array( 'ID', 'user_registered' ) );
        foreach($users as $user){
         $time = $user->user_registered;
          if(strtotime($time) < strtotime('-30 days')) {
            $u->remove_role( 'whatever-role' );
          }
        }
       ```
   
 *  Thread Starter [pits24](https://wordpress.org/support/users/pits24/)
 * (@pits24)
 * [5 years, 11 months ago](https://wordpress.org/support/topic/user-role-plugin-3/#post-13027800)
 * Thanks for the reply. I am trying to do this but when i run the cron function
   to test all the users in the role gets suspended regardless of registration time.
   Can you see what mistake i am making in the logic.
 *     ```
       $args1 = array(
                   'role' => 'um_sub-admin',
                   'date_query' => array(
                       'after' => date('Y-m-d', strtotime('-30 days'))
                   ) 
               );
   
        $sub = get_users($args1);
   
       foreach ($sub as $user) {
           $udata = get_userdata( $user->ID );
           $registered = $udata->user_registered;
           $reg_date = date( "Y m d", strtotime( $registered ) );
           if( $reg_date < strtotime('-30 days') ) {
   
               $udata->remove_role( 'um_sub-admin' );
               $udata->add_role( 'suspended' );
           }
   
       }
       ```
   
 *  [corrinarusso](https://wordpress.org/support/users/corrinarusso/)
 * (@corrinarusso)
 * [5 years, 11 months ago](https://wordpress.org/support/topic/user-role-plugin-3/#post-13029698)
 * Are you saying this condition is always met ?
    if( $reg_date < strtotime(‘-30
   days’) ) {
 * Can you print this to the console and include it here ?
    $reg_date = date( “Y
   m d”, strtotime( $registered ) );
 *  Thread Starter [pits24](https://wordpress.org/support/users/pits24/)
 * (@pits24)
 * [5 years, 11 months ago](https://wordpress.org/support/topic/user-role-plugin-3/#post-13029763)
 * It worked out! I got the users with exact 30 days passed with date_query.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘User Role Plugin’ is closed to new replies.

 * In: [Networking WordPress](https://wordpress.org/support/forum/multisite/)
 * 4 replies
 * 2 participants
 * Last reply from: [pits24](https://wordpress.org/support/users/pits24/)
 * Last activity: [5 years, 11 months ago](https://wordpress.org/support/topic/user-role-plugin-3/#post-13029763)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
