0

I have issues getting this code to work. I want to BUGSexpdate which has a set date to remove a role when the date is reached as I want to "rent" out movies. This code I found on a similar thread does not work.

Change the user role after x days

add_action( 'change_expired_users_hook', 'change_expired_users_role' );

function change_expired_users_role(){
    $args = array(
    'meta_key' => 'BUGSexpdate',
    'meta_value' => time(),
    'meta_compare' => `<=`,
    'fields' => array('ID')
    );

    $users = get_users($args);

    if( empty( $users ) )
        return;

    foreach( $users as $user ){
        
        // Remove old role
        $user->remove_role( 'bugs' ); 

        // Add new role
        $user->add_role( 'customer' );
                
    }
}
3
  • there's no information about what BUGSexpdate contains and the format of the data, and it doesn't look like you've confirmed if it finds the users or not. Your cron job registration is also missing too so it's not possible to check if the problem is there. What is BUGSexpdate exactly? If it does not do what you want it to do, what does it do instead?
    – Tom J Nowell
    Jul 19 at 12:34
  • Guess you could work with transient's, if False: user doesn't have the movie anymore. developer.wordpress.org/apis/handbook/transients
    – grumpyp
    Jul 19 at 13:34
  • BUGSexpdate is the expiry date that get puts into the user meta when purchasing, it is the current date + 7 days. Jul 20 at 12:19

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.