Ticket #28635: 28635.2.patch
File 28635.2.patch, 7.9 KB (added by , 9 years ago) |
---|
-
src/wp-includes/functions.php
IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8
2456 2456 $title = ''; 2457 2457 } 2458 2458 2459 if ( defined( 'DOING_AJAX' ) && DOING_AJAX) {2459 if ( ( defined( 'DOING_AJAX' ) && DOING_AJAX ) || ( defined( 'DOING_CRON' ) && DOING_CRON ) ) { 2460 2460 /** 2461 2461 * Filter callback for killing WordPress execution for AJAX requests. 2462 2462 * -
src/wp-cron.php
IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8
9 9 * @package WordPress 10 10 */ 11 11 12 ignore_user_abort( true);12 ignore_user_abort( true ); 13 13 14 if ( !empty($_POST) || defined('DOING_AJAX') || defined('DOING_CRON') ) 15 die(); 14 if ( defined( 'DOING_AJAX' ) || defined( 'DOING_CRON' ) ) { 15 die( 'doing_ajax_or_doing_cron' ); 16 } 16 17 17 18 /** 18 19 * Tell WordPress we are doing the CRON task. 19 20 * 20 21 * @var bool 21 22 */ 22 define( 'DOING_CRON', true);23 define( 'DOING_CRON', true ); 23 24 24 if ( ! defined('ABSPATH') ) {25 if ( ! defined( 'ABSPATH' ) ) { 25 26 /** Set up WordPress environment */ 26 27 require_once( dirname( __FILE__ ) . '/wp-load.php' ); 27 28 } 28 29 29 30 /** 31 * Default handler for a WP Cron exit 32 * 33 * @param string $code 34 */ 35 function wp_cron_default_exit_handler( $code ) { 36 do_action( 'wp_cron_response_close', $code ); 37 if ( 'bad_post_request_or_doing_ajax_or_doing_cron' === $code ) { 38 $response = 400; 39 } elseif ( 'empty_cron_array' === $code ) { 40 $response = 204; 41 } elseif ( 'no_scheduled_actions_due' === $code ) { 42 $response = 204; 43 } elseif ( 'cron_locked' === $code ) { 44 $response = 403; 45 } elseif ( 'cron_lock_check_fail' === $code ) { 46 $response = 400; 47 } elseif ( 'ok_exit_prematurely' === $code ) { 48 $response = 200; 49 } elseif ( 'ok' === $code ) { 50 $response = 200; 51 } else { 52 $response = 500; 53 } 54 if ( ! headers_sent() ) { 55 header( 'Content-Type: text/plain' ); 56 status_header( $response ); 57 } 58 wp_die( $code, '', compact( $response ) ); 59 } 60 61 /** 62 * Filter callback for killing WordPress execution of WP_Cron. 63 * 64 * @param callable $wp_cron_exit_handler Callback function name. 65 */ 66 $wp_cron_exit_handler = apply_filters( 'wp_cron_exit_handler', 'wp_cron_default_exit_handler' ); 67 68 if ( ! empty( $_POST ) ) { 69 $wp_cron_exit_handler( 'bad_post_request' ); 70 } 71 72 /** 30 73 * Retrieves the cron lock. 31 74 * 32 75 * Returns the uncached `doing_cron` transient. … … 48 91 $value = wp_cache_get( 'doing_cron', 'transient', true ); 49 92 } else { 50 93 $row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", '_transient_doing_cron' ) ); 51 if ( is_object( $row ) ) 94 if ( is_object( $row ) ) { 52 95 $value = $row->option_value; 53 } 96 } 97 } 54 98 55 99 return $value; 56 100 } 57 101 58 if ( false === $crons = _get_cron_array() ) 59 die(); 102 if ( false === $crons = _get_cron_array() ) { 103 $wp_cron_exit_handler( 'empty_cron_array' ); 104 } 60 105 61 106 $keys = array_keys( $crons ); 62 107 $gmt_time = microtime( true ); 63 108 64 if ( isset($keys[0]) && $keys[0] > $gmt_time ) 65 die(); 109 if ( isset( $keys[0] ) && $keys[0] > $gmt_time ) { 110 $wp_cron_exit_handler( 'no_scheduled_actions_due' ); 111 } 66 112 67 113 68 114 // The cron lock: a unix timestamp from when the cron was spawned. … … 70 116 71 117 // Use global $doing_wp_cron lock otherwise use the GET lock. If no lock, trying grabbing a new lock. 72 118 if ( empty( $doing_wp_cron ) ) { 73 if ( empty( $_GET[ 'doing_wp_cron'] ) ) {119 if ( empty( $_GET['doing_wp_cron'] ) ) { 74 120 // Called from external script/job. Try setting a lock. 75 if ( $doing_cron_transient && ( $doing_cron_transient + WP_CRON_LOCK_TIMEOUT > $gmt_time ) ) 76 return; 121 if ( $doing_cron_transient && ( $doing_cron_transient + WP_CRON_LOCK_TIMEOUT > $gmt_time ) ) { 122 $wp_cron_exit_handler( 'cron_locked' ); 123 } 77 124 $doing_cron_transient = $doing_wp_cron = sprintf( '%.22F', microtime( true ) ); 78 125 set_transient( 'doing_cron', $doing_wp_cron ); 79 126 } else { 80 $doing_wp_cron = $_GET[ 'doing_wp_cron'];127 $doing_wp_cron = $_GET['doing_wp_cron']; 81 128 } 82 129 } 83 130 … … 85 132 * The cron lock (a unix timestamp set when the cron was spawned), 86 133 * must match $doing_wp_cron (the "key"). 87 134 */ 88 if ( $doing_cron_transient != $doing_wp_cron ) 89 return; 135 if ( $doing_cron_transient != $doing_wp_cron ) { 136 $wp_cron_exit_handler( 'cron_lock_check_fail' ); 137 } 90 138 139 /** 140 * Fires before looping through all the scheduled hooks to filter out those that don't need to run yet. 141 * 142 * @param array $crons The scheduled hooks. 143 */ 144 do_action( 'wp_cron_before_crons_loop', $crons ); 91 145 foreach ( $crons as $timestamp => $cronhooks ) { 92 if ( $timestamp > $gmt_time ) 146 if ( $timestamp > $gmt_time ) { 93 147 break; 148 } 94 149 150 /** 151 * Fires before looping through the scheduled hooks of a timestamp. 152 * 153 * @param array $cronhooks The scheduled hooks of a specific timestamp. 154 */ 155 do_action( 'wp_cron_before_cronhooks_loop', $cronhooks ); 95 156 foreach ( $cronhooks as $hook => $keys ) { 96 157 158 /** 159 * Fires before looping through the scheduled hook's keys. 160 * 161 * @param array $keys The scheduled hook's keys. 162 */ 163 do_action( 'wp_cron_before_keys_loop', $keys ); 97 164 foreach ( $keys as $k => $v ) { 98 165 99 166 $schedule = $v['schedule']; 100 167 101 168 if ( $schedule != false ) { 102 $new_args = array( $timestamp, $schedule, $hook, $v['args']);103 call_user_func_array( 'wp_reschedule_event', $new_args);169 $new_args = array( $timestamp, $schedule, $hook, $v['args'] ); 170 call_user_func_array( 'wp_reschedule_event', $new_args ); 104 171 } 105 172 106 173 wp_unschedule_event( $timestamp, $hook, $v['args'] ); 107 174 108 175 /** 176 * Fires before a scheduled hook is fired. 177 * 178 * @param string $hook Name of the hook that was scheduled to be fired. 179 * @param array $args The arguments to be passed to the hook. 180 * @param string $schedule The interval which the scheduled hook runs at. 181 * @param int $timestamp The timestamp of when the hook was scheduled to fire. 182 */ 183 do_action( 'wp_cron_before_hook', $hook, $v['args'], $schedule, $timestamp ); 184 185 /** 109 186 * Fires scheduled events. 110 187 * 111 188 * @ignore … … 114 191 * @param string $hook Name of the hook that was scheduled to be fired. 115 192 * @param array $args The arguments to be passed to the hook. 116 193 */ 117 194 do_action_ref_array( $hook, $v['args'] ); 118 195 196 /** 197 * Fires after a scheduled hook is fired. 198 * 199 * @param string $hook Name of the scheduled hook that fired. 200 * @param array $args The arguments passed to the hook. 201 * @param string $schedule The interval which the scheduled hook ran at. 202 * @param int $timestamp The timestamp of when the hook was scheduled to fire. 203 */ 204 do_action( 'wp_cron_after_hook', $hook, $v['args'], $schedule, $timestamp ); 205 119 206 // If the hook ran too long and another cron process stole the lock, quit. 120 if ( _get_cron_lock() != $doing_wp_cron ) 121 return; 122 } 123 } 124 } 207 if ( _get_cron_lock() != $doing_wp_cron ) { 208 $wp_cron_exit_handler( 'ok_exit_prematurely' ); 209 } 210 } 211 212 /** 213 * Fires after looping through the scheduled hook's keys. 214 * 215 * @param array $keys The scheduled hook's keys. 216 */ 217 do_action( 'wp_cron_after_keys_loop', $keys ); 218 } 125 219 126 if ( _get_cron_lock() == $doing_wp_cron ) 220 /** 221 * Fires after looping through the scheduled hooks of a timestamp. 222 * 223 * @param array $cronhooks The scheduled hooks of a specific timestamp. 224 */ 225 do_action( 'wp_cron_after_cronhooks_loop', $cronhooks ); 226 } 227 /** 228 * Fires before looping through all the scheduled hooks to filter out those that don't need to run yet. 229 * 230 * @param array $crons The scheduled hooks. 231 */ 232 do_action( 'wp_cron_after_crons_loop', $crons ); 233 234 if ( _get_cron_lock() == $doing_wp_cron ) { 127 235 delete_transient( 'doing_cron' ); 236 } 128 237 129 die();238 $wp_cron_exit_handler( 'ok' );