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' );
}
}
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 isBUGSexpdate
exactly? If it does not do what you want it to do, what does it do instead?