Make WordPress Core

Ticket #9005: 9005.patch

File 9005.patch, 4.5 KB (added by azaozz, 16 years ago)
  • wp-cron.php

     
    1111
    1212ignore_user_abort(true);
    1313
    14 /**
    15  * Tell WordPress we are doing the CRON task.
    16  *
    17  * @var bool
    18  */
    19 define('DOING_CRON', true);
    20 /** Setup WordPress environment */
    21 require_once('./wp-load.php');
     14if ( defined('ABSPATH') ) {
     15        if ( !empty($_POST) || defined('DOING_AJAX') || defined('DOING_CRON') )
     16                return;
    2217
     18        /**
     19         * Tell WordPress we are doing the CRON task.
     20         *
     21         * @var bool
     22         */
     23        define('DOING_CRON', true);
     24        wp_redirect(stripslashes($_SERVER['REQUEST_URI']));
     25        flush();
     26} else {
     27        define('DOING_CRON', true);
     28
     29        /** Setup WordPress environment */
     30        require_once('./wp-load.php');
     31}
     32
    2333$local_time = time();
    2434
    25 $crons = _get_cron_array();
     35if ( !isset($crons) ) {
     36        if ( false === $crons = _get_cron_array() )
     37                die();
     38}
     39
    2640$keys = array_keys( $crons );
    2741
    28 if (!is_array($crons) || $keys[0] > $local_time) {
    29         update_option('doing_cron', 0);
    30         return;
    31 }
     42if ( isset($keys[0]) && $keys[0] > $local_time )
     43        die();
    3244
    3345foreach ($crons as $timestamp  => $cronhooks) {
    34 
    3546        if ( $timestamp > $local_time )
    3647                break;
    3748
     
    5364        }
    5465}
    5566
    56 update_option('doing_cron', 0);
    57 
    5867die();
    59 
    60 ?>
  • wp-includes/cron.php

     
    170170        if ( !$timer_accurate )
    171171                return;
    172172
    173         //sanity check
    174         $crons = _get_cron_array();
    175         if ( !is_array($crons) )
    176                 return;
    177 
    178         $keys = array_keys( $crons );
    179         $timestamp =  $keys[0];
    180         if ( $timestamp > $local_time )
    181                 return;
    182 
    183173        /*
    184174        * multiple processes on multiple web servers can run this code concurrently
    185175        * try to make this as atomic as possible by setting doing_cron switch
    186176        */
    187177        $flag = get_option('doing_cron');
    188178
    189         // clean up potential invalid value resulted from various system chaos
    190         if ( $flag != 0 ) {
    191                 if ( $flag > $local_time + 10*60 || $flag < $local_time - 10*60 ) {
    192                         update_option('doing_cron', 0);
    193                         $flag = 0;
    194                 }
    195         }
     179        if ( $flag > $local_time + 10*60 )
     180                $flag = 0;
    196181
    197         //don't run if another process is currently running it
    198         if ( $flag > $local_time )
     182        // don't run if another process is currently running it or more than once every 60 sec.
     183        if ( $flag + 60 > $local_time )
    199184                return;
    200185
    201         update_option( 'doing_cron', $local_time + 30 );
     186        //sanity check
     187        $crons = _get_cron_array();
     188        if ( !is_array($crons) )
     189                return;
    202190
    203         add_action('wp_head', 'spawn_cron_request');
     191        $keys = array_keys( $crons );
     192        if ( isset($keys[0]) && $keys[0] > $local_time )
     193                return;
     194
     195        update_option( 'doing_cron', $local_time );
     196
     197        include_once(ABSPATH . 'wp-cron.php');
    204198}
    205199
    206200/**
     
    213207function wp_cron() {
    214208
    215209        // Prevent infinite loops caused by lack of wp-cron.php
    216         if ( strpos($_SERVER['REQUEST_URI'], '/wp-cron.php') !== false )
     210        if ( strpos($_SERVER['REQUEST_URI'], '/wp-cron.php') !== false || ( defined('DISABLE_WP_CRON') && DISABLE_WP_CRON ) )
    217211                return;
    218212
    219         $crons = _get_cron_array();
    220 
    221         if ( !is_array($crons) )
     213        if ( false === $crons = _get_cron_array() )
    222214                return;
    223215
     216        $local_time = time();
    224217        $keys = array_keys( $crons );
    225         if ( isset($keys[0]) && $keys[0] > time() )
     218        if ( isset($keys[0]) && $keys[0] > $local_time )
    226219                return;
    227220
    228         $local_time = time();
    229221        $schedules = wp_get_schedules();
    230222        foreach ( $crons as $timestamp => $cronhooks ) {
    231223                if ( $timestamp > $local_time ) break;
     
    370362        return true;
    371363}
    372364
    373 function spawn_cron_request() {
    374365?>
    375 <script type="text/javascript">
    376 /* <![CDATA[ */
    377 window.setTimeout(function(){var x;if(window.XMLHttpRequest){x=new XMLHttpRequest();}else{try{x=new ActiveXObject('Msxml2.XMLHTTP');}catch(e){try{x=new ActiveXObject('Microsoft.XMLHTTP');}catch(e){};}}if(x){x.open('GET','<?php echo get_option('siteurl'); ?>/wp-cron.php?'+(new Date()).getTime(), true);x.send('');}},10);
    378 /* ]]> */
    379 </script>
    380 <?php
    381 }
    382 
    383 ?>
  • wp-includes/default-filters.php

     
    176176add_action('wp_head', 'wp_generator');
    177177add_action('wp_footer', 'wp_print_footer_scripts');
    178178if(!defined('DOING_CRON'))
    179         add_action('init', 'wp_cron');
     179        add_action('sanitize_comment_cookies', 'wp_cron');
    180180add_action('do_feed_rdf', 'do_feed_rdf', 10, 1);
    181181add_action('do_feed_rss', 'do_feed_rss', 10, 1);
    182182add_action('do_feed_rss2', 'do_feed_rss2', 10, 1);