SHARE
TWEET

Untitled

advokatb Jun 19th, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. add_action('mymasi_cron_event', 'mymasi_cron_job');
  3.  
  4. function mymasi_cron_job()
  5. {
  6.     $userPosts = mms_users_to_be_notified();
  7.  
  8.     var_dump('fake cron start...' . '<br><br>');
  9.     $cron_log = "cron start...<br><br>";
  10.     $cron_log .= 'Users in list: ' . count($userPosts) . '<br><br>';
  11.  
  12.     foreach ($userPosts as $userPost) {
  13.         $now = time();
  14.         $email = get_field('user_email', $userPost->ID);
  15.         $user = get_user_by('email', $email);
  16.         $importantDate = get_field('important_notification_expiration', $userPost->ID);
  17.         $myDate = get_field('my_custom_notification_expiration', $userPost->ID);
  18.  
  19.         $disableMy = get_field('my_custom_notification_disable', $userPost->ID);
  20.         $disableImportant = get_field('important_notification_disable', $userPost->ID);
  21.  
  22.         if ($user) {
  23.  
  24.             $notify = new My_Mayan_Sign_Notifications($user->ID);
  25.  
  26.             if ($importantDate != null) {
  27.                 if (strtotime($importantDate) > $now) {
  28.                     if ($disableImportant != 'disable') {
  29.                         $cron_log .= 'sending important notification for ' . $email . ' ';
  30.                         $cron_log .= $notify->handleImportantNotification() . '<br>';
  31.                     }
  32.                 }
  33.             }
  34.  
  35.             if ($myDate != null) {
  36.                 if (strtotime($myDate) > $now) {
  37.                     if ($disableMy != 'disable') {
  38.                         $cron_log .= 'sending my notification for ' . $email . ' ';
  39.                         $cron_log .= $notify->handleMyMayanNotification() . '<br>';
  40.                     }
  41.                 }
  42.             }
  43.         } else {
  44.             // User from this post doesn't exist
  45.             // Send it to review
  46.             wp_update_post(array(
  47.                 'ID' => $userPost->ID,
  48.                 'post_status' => 'pending'
  49.             ));
  50.         }
  51.     }
  52.  
  53.     mms_cron_logger($cron_log);
  54. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top