diff --git src/wp-cron.php src/wp-cron.php
index 2b965dd..3df77b5 100644
|
|
|
|
| 9 | 9 | * @package WordPress |
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | | ignore_user_abort(true); |
| 13 | | |
| 14 | | if ( !empty($_POST) || defined('DOING_AJAX') || defined('DOING_CRON') ) |
| 15 | | die(); |
| | 12 | ignore_user_abort( true ); |
| 16 | 13 | |
| 17 | 14 | /** |
| 18 | 15 | * Tell WordPress we are doing the CRON task. |
| 19 | 16 | * |
| 20 | 17 | * @var bool |
| 21 | 18 | */ |
| 22 | | define('DOING_CRON', true); |
| | 19 | define( 'DOING_CRON', true ); |
| 23 | 20 | |
| 24 | | if ( !defined('ABSPATH') ) { |
| | 21 | if ( ! defined( 'ABSPATH' ) ) { |
| 25 | 22 | /** Set up WordPress environment */ |
| 26 | 23 | require_once( dirname( __FILE__ ) . '/wp-load.php' ); |
| 27 | 24 | } |
| 28 | 25 | |
| | 26 | /** |
| | 27 | * Default handler for a WP Cron exit |
| | 28 | * |
| | 29 | * @param string $code |
| | 30 | */ |
| | 31 | function wp_cron_default_exit_handler( $code ) { |
| | 32 | do_action( 'wp_cron_response_close', $code ); |
| | 33 | if ( 'bad_post_request_or_doing_ajax_or_doing_cron' === $code ) { |
| | 34 | $response = 400; |
| | 35 | } elseif ( 'empty_cron_array' === $code ) { |
| | 36 | $response = 204; |
| | 37 | } elseif ( 'no_scheduled_actions_due' === $code ) { |
| | 38 | $response = 204; |
| | 39 | } elseif ( 'cron_locked' === $code ) { |
| | 40 | $response = 403; |
| | 41 | } elseif ( 'cron_lock_check_fail' === $code ) { |
| | 42 | $response = 400; |
| | 43 | } elseif ( 'ok_exit_prematurely' === $code ) { |
| | 44 | $response = 200; |
| | 45 | } elseif ( 'ok' === $code ) { |
| | 46 | $response = 200; |
| | 47 | } else { |
| | 48 | $response = 500; |
| | 49 | } |
| | 50 | if ( ! headers_sent() ) { |
| | 51 | header( 'Content-Type: text/plain' ); |
| | 52 | status_header( $response ); |
| | 53 | } |
| | 54 | wp_die( $code, '', compact( $response ) ); |
| | 55 | } |
| | 56 | |
| | 57 | /** |
| | 58 | * @var string $wp_cron_exit_handler |
| | 59 | * @todo docs |
| | 60 | */ |
| | 61 | $wp_cron_exit_handler = apply_filters( 'wp_cron_exit_handler', 'wp_cron_default_exit_handler' ); |
| | 62 | |
| | 63 | if ( ! empty( $_POST ) || defined( 'DOING_AJAX' ) || defined( 'DOING_CRON' ) ) { |
| | 64 | $wp_cron_exit_handler( 'bad_post_request_or_doing_ajax_or_doing_cron' ); |
| | 65 | } |
| | 66 | |
| 29 | 67 | // Uncached doing_cron transient fetch |
| 30 | 68 | function _get_cron_lock() { |
| 31 | 69 | global $wpdb; |
| … |
… |
function _get_cron_lock() { |
| 39 | 77 | $value = wp_cache_get( 'doing_cron', 'transient', true ); |
| 40 | 78 | } else { |
| 41 | 79 | $row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", '_transient_doing_cron' ) ); |
| 42 | | if ( is_object( $row ) ) |
| | 80 | if ( is_object( $row ) ) { |
| 43 | 81 | $value = $row->option_value; |
| | 82 | } |
| 44 | 83 | } |
| 45 | 84 | |
| 46 | 85 | return $value; |
| 47 | 86 | } |
| 48 | 87 | |
| 49 | | if ( false === $crons = _get_cron_array() ) |
| 50 | | die(); |
| | 88 | if ( false === $crons = _get_cron_array() ) { |
| | 89 | $wp_cron_exit_handler( 'empty_cron_array' ); |
| | 90 | } |
| 51 | 91 | |
| 52 | 92 | $keys = array_keys( $crons ); |
| 53 | 93 | $gmt_time = microtime( true ); |
| 54 | 94 | |
| 55 | | if ( isset($keys[0]) && $keys[0] > $gmt_time ) |
| 56 | | die(); |
| | 95 | if ( isset( $keys[0] ) && $keys[0] > $gmt_time ) { |
| | 96 | $wp_cron_exit_handler( 'no_scheduled_actions_due' ); |
| | 97 | } |
| 57 | 98 | |
| 58 | | $doing_cron_transient = get_transient( 'doing_cron'); |
| | 99 | $doing_cron_transient = get_transient( 'doing_cron' ); |
| 59 | 100 | |
| 60 | 101 | // Use global $doing_wp_cron lock otherwise use the GET lock. If no lock, trying grabbing a new lock. |
| 61 | 102 | if ( empty( $doing_wp_cron ) ) { |
| 62 | | if ( empty( $_GET[ 'doing_wp_cron' ] ) ) { |
| | 103 | if ( empty( $_GET['doing_wp_cron'] ) ) { |
| 63 | 104 | // Called from external script/job. Try setting a lock. |
| 64 | | if ( $doing_cron_transient && ( $doing_cron_transient + WP_CRON_LOCK_TIMEOUT > $gmt_time ) ) |
| 65 | | return; |
| | 105 | if ( $doing_cron_transient && ( $doing_cron_transient + WP_CRON_LOCK_TIMEOUT > $gmt_time ) ) { |
| | 106 | $wp_cron_exit_handler( 'cron_locked' ); |
| | 107 | } |
| 66 | 108 | $doing_cron_transient = $doing_wp_cron = sprintf( '%.22F', microtime( true ) ); |
| 67 | 109 | set_transient( 'doing_cron', $doing_wp_cron ); |
| 68 | 110 | } else { |
| 69 | | $doing_wp_cron = $_GET[ 'doing_wp_cron' ]; |
| | 111 | $doing_wp_cron = $_GET['doing_wp_cron']; |
| 70 | 112 | } |
| 71 | 113 | } |
| 72 | 114 | |
| 73 | 115 | // Check lock |
| 74 | | if ( $doing_cron_transient != $doing_wp_cron ) |
| 75 | | return; |
| | 116 | if ( $doing_cron_transient != $doing_wp_cron ) { |
| | 117 | $wp_cron_exit_handler( 'cron_lock_check_fail' ); |
| | 118 | } |
| 76 | 119 | |
| | 120 | /** |
| | 121 | * @todo docs |
| | 122 | */ |
| | 123 | do_action( 'wp_cron_before_crons_loop', $crons ); |
| 77 | 124 | foreach ( $crons as $timestamp => $cronhooks ) { |
| 78 | | if ( $timestamp > $gmt_time ) |
| | 125 | if ( $timestamp > $gmt_time ) { |
| 79 | 126 | break; |
| | 127 | } |
| 80 | 128 | |
| | 129 | /** |
| | 130 | * @todo docs |
| | 131 | */ |
| | 132 | do_action( 'wp_cron_before_cronhooks_loop', $cronhooks ); |
| 81 | 133 | foreach ( $cronhooks as $hook => $keys ) { |
| 82 | 134 | |
| | 135 | /** |
| | 136 | * @todo docs |
| | 137 | */ |
| | 138 | do_action( 'wp_cron_before_keys_loop', $keys ); |
| 83 | 139 | foreach ( $keys as $k => $v ) { |
| 84 | 140 | |
| 85 | 141 | $schedule = $v['schedule']; |
| 86 | 142 | |
| 87 | 143 | if ( $schedule != false ) { |
| 88 | | $new_args = array($timestamp, $schedule, $hook, $v['args']); |
| 89 | | call_user_func_array('wp_reschedule_event', $new_args); |
| | 144 | $new_args = array( $timestamp, $schedule, $hook, $v['args'] ); |
| | 145 | call_user_func_array( 'wp_reschedule_event', $new_args ); |
| 90 | 146 | } |
| 91 | 147 | |
| 92 | 148 | wp_unschedule_event( $timestamp, $hook, $v['args'] ); |
| 93 | 149 | |
| 94 | 150 | /** |
| | 151 | * @todo docs |
| | 152 | */ |
| | 153 | do_action( 'wp_cron_before_hook', $hook, $v['args'], $schedule, $timestamp ); |
| | 154 | |
| | 155 | /** |
| 95 | 156 | * Fires scheduled events. |
| 96 | 157 | * |
| 97 | 158 | * @internal |
| … |
… |
foreach ( $crons as $timestamp => $cronhooks ) { |
| 100 | 161 | * @param string $hook Name of the hook that was scheduled to be fired. |
| 101 | 162 | * @param array $args The arguments to be passed to the hook. |
| 102 | 163 | */ |
| 103 | | do_action_ref_array( $hook, $v['args'] ); |
| | 164 | do_action_ref_array( $hook, $v['args'] ); |
| | 165 | |
| | 166 | /** |
| | 167 | * @todo docs |
| | 168 | */ |
| | 169 | do_action( 'wp_cron_after_hook', $hook, $v['args'], $schedule, $timestamp ); |
| 104 | 170 | |
| 105 | 171 | // If the hook ran too long and another cron process stole the lock, quit. |
| 106 | | if ( _get_cron_lock() != $doing_wp_cron ) |
| 107 | | return; |
| | 172 | if ( _get_cron_lock() != $doing_wp_cron ) { |
| | 173 | $wp_cron_exit_handler( 'ok_exit_prematurely' ); |
| | 174 | } |
| 108 | 175 | } |
| | 176 | |
| | 177 | /** |
| | 178 | * @todo docs |
| | 179 | */ |
| | 180 | do_action( 'wp_cron_after_keys_loop', $keys ); |
| 109 | 181 | } |
| | 182 | |
| | 183 | /** |
| | 184 | * @todo docs |
| | 185 | */ |
| | 186 | do_action( 'wp_cron_after_cronhooks_loop', $cronhooks ); |
| 110 | 187 | } |
| | 188 | /** |
| | 189 | * @todo docs |
| | 190 | */ |
| | 191 | do_action( 'wp_cron_after_crons_loop', $crons ); |
| 111 | 192 | |
| 112 | | if ( _get_cron_lock() == $doing_wp_cron ) |
| | 193 | if ( _get_cron_lock() == $doing_wp_cron ) { |
| 113 | 194 | delete_transient( 'doing_cron' ); |
| | 195 | } |
| 114 | 196 | |
| 115 | | die(); |
| | 197 | $wp_cron_exit_handler( 'ok' ); |
diff --git src/wp-includes/functions.php src/wp-includes/functions.php
index 33ace42..bc305e8 100644
|
|
|
function wp_nonce_ays( $action ) { |
| 2242 | 2242 | * @param string|array $args Optional arguments to control behavior. |
| 2243 | 2243 | */ |
| 2244 | 2244 | function wp_die( $message = '', $title = '', $args = array() ) { |
| 2245 | | if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { |
| | 2245 | if ( ( defined( 'DOING_AJAX' ) && DOING_AJAX ) || ( defined( 'DOING_CRON' ) && DOING_CRON ) ) { |
| 2246 | 2246 | /** |
| 2247 | 2247 | * Filter callback for killing WordPress execution for AJAX requests. |
| 2248 | 2248 | * |