Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- add_action('mymasi_cron_event', 'mymasi_cron_job');
- function mymasi_cron_job()
- {
- $userPosts = mms_users_to_be_notified();
- var_dump('fake cron start...' . '<br><br>');
- $cron_log = "cron start...<br><br>";
- $cron_log .= 'Users in list: ' . count($userPosts) . '<br><br>';
- foreach ($userPosts as $userPost) {
- $now = time();
- $email = get_field('user_email', $userPost->ID);
- $user = get_user_by('email', $email);
- $importantDate = get_field('important_notification_expiration', $userPost->ID);
- $myDate = get_field('my_custom_notification_expiration', $userPost->ID);
- $disableMy = get_field('my_custom_notification_disable', $userPost->ID);
- $disableImportant = get_field('important_notification_disable', $userPost->ID);
- if ($user) {
- $notify = new My_Mayan_Sign_Notifications($user->ID);
- if ($importantDate != null) {
- if (strtotime($importantDate) > $now) {
- if ($disableImportant != 'disable') {
- $cron_log .= 'sending important notification for ' . $email . ' ';
- $cron_log .= $notify->handleImportantNotification() . '<br>';
- }
- }
- }
- if ($myDate != null) {
- if (strtotime($myDate) > $now) {
- if ($disableMy != 'disable') {
- $cron_log .= 'sending my notification for ' . $email . ' ';
- $cron_log .= $notify->handleMyMayanNotification() . '<br>';
- }
- }
- }
- } else {
- // User from this post doesn't exist
- // Send it to review
- wp_update_post(array(
- 'ID' => $userPost->ID,
- 'post_status' => 'pending'
- ));
- }
- }
- mms_cron_logger($cron_log);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement