/**
  * Alternative function to the current wp_cron function that would usually executed on sanitize_comment_cookies
  */
 public function validate_cron_request()
 {
     // make sure we're in wp-cron.php
     if (false !== strpos($_SERVER['REQUEST_URI'], '/wp-cron.php')) {
         // grab the necessary secret string
         if (defined('WP_CRON_CONTROL_SECRET')) {
             $secret = WP_CRON_CONTROL_SECRET;
         } else {
             $secret = $this->settings['secret_string'];
         }
         // make sure a secret string is provided in the ur
         if (isset($_GET[$secret])) {
             // check if there is already a cron request running
             $local_time = time();
             if (function_exists('_get_cron_lock')) {
                 $flag = _get_cron_lock();
             } else {
                 $flag = get_transient('doing_cron');
             }
             if (defined('WP_CRON_LOCK_TIMEOUT')) {
                 $timeout = WP_CRON_LOCK_TIMEOUT;
             } else {
                 $timeout = 60;
             }
             if ($flag > $local_time + 10 * $timeout) {
                 $flag = 0;
             }
             // don't run if another process is currently running it or more than once every 60 sec.
             if ($flag + $timeout > $local_time) {
                 die('another cron process running or previous not older than 60 secs');
             }
             // set a transient to allow locking down parallel requests
             set_transient('doing_cron', $local_time);
             // make sure the request also validates in wp-cron.php
             global $doing_wp_cron;
             $doing_wp_cron = $local_time;
             // if settings allow it validate if there are any scheduled posts without a cron event
             if (1 == self::instance()->settings['enable_scheduled_post_validation']) {
                 $this->validate_scheduled_posts();
             }
             return true;
         }
         // something went wrong
         die('invalid secret string');
     }
     // for all other cases disable wp-cron.php and spawn_cron() by telling the system it's already running
     if (!defined('DOING_CRON')) {
         define('DOING_CRON', true);
     }
     // and also disable the wp_cron() call execution
     if (!defined('DISABLE_WP_CRON')) {
         define('DISABLE_WP_CRON', true);
     }
     return false;
 }
예제 #2
0
        break;
    }
    foreach ($cronhooks as $hook => $keys) {
        foreach ($keys as $k => $v) {
            $schedule = $v['schedule'];
            if ($schedule != false) {
                $new_args = array($timestamp, $schedule, $hook, $v['args']);
                call_user_func_array('wp_reschedule_event', $new_args);
            }
            wp_unschedule_event($timestamp, $hook, $v['args']);
            /**
             * Fires scheduled events.
             *
             * @ignore
             * @since 2.1.0
             *
             * @param string $hook Name of the hook that was scheduled to be fired.
             * @param array  $args The arguments to be passed to the hook.
             */
            do_action_ref_array($hook, $v['args']);
            // If the hook ran too long and another cron process stole the lock, quit.
            if (_get_cron_lock() != $doing_wp_cron) {
                return;
            }
        }
    }
}
if (_get_cron_lock() == $doing_wp_cron) {
    delete_transient('doing_cron');
}
die;
예제 #3
0
        $doing_nxt_cron = $_GET['doing_nxt_cron'];
    }
}
// Check lock
if ($doing_cron_transient != $doing_nxt_cron) {
    return;
}
foreach ($crons as $timestamp => $cronhooks) {
    if ($timestamp > $local_time) {
        break;
    }
    foreach ($cronhooks as $hook => $keys) {
        foreach ($keys as $k => $v) {
            $schedule = $v['schedule'];
            if ($schedule != false) {
                $new_args = array($timestamp, $schedule, $hook, $v['args']);
                call_user_func_array('nxt_reschedule_event', $new_args);
            }
            nxt_unschedule_event($timestamp, $hook, $v['args']);
            do_action_ref_array($hook, $v['args']);
            // If the hook ran too long and another cron process stole the lock, quit.
            if (_get_cron_lock() != $doing_nxt_cron) {
                return;
            }
        }
    }
}
if (_get_cron_lock() == $doing_nxt_cron) {
    delete_transient('doing_cron');
}
die;