Forum Replies Created

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter pits24

    (@pits24)

    It worked out! I got the users with exact 30 days passed with date_query.

    Thread Starter pits24

    (@pits24)

    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' );
        }
    
    }
    
Viewing 2 replies - 1 through 2 (of 2 total)