Hello,
I’m trying to add a condition to a cronjob to check if the user role is “s2member_level1” for 7 days, and then it should allow an upgrade for the user to level 2.
The current code I have now (see below) checks all users and upgrades them to level 2 instead of just the level 1 users. I want to modify the code below but I’m not quite sure where to put the new condition and how it has to be formatted. If somebody can help this php noob out on this it would be very much appreciated.
Thanks for your time and help!
Current code:
<?php add_action('init', function () { if(!empty($_GET['my_cron_job']) && $_GET['my_cron_job'] === 'updatelevel1to2') { foreach(get_users() as $user) { $user = new WP_User($user->ID); $_7_days_ago = strtotime('-7 days'); if(s2member_registration_time($user->ID) <= $_7_days_ago) { # A Member for at least 7 days. # Promote them now to Level #2. if(!$user->has_cap("access_s2member_level2")) $user->set_role("s2member_level2"); } } exit; } });