Make WordPress Core

Ticket #17957: 17957.diff

File 17957.diff, 1.8 KB (added by pento, 10 years ago)
  • src/wp-includes/cron.php

     
    266266        if ( strpos($_SERVER['REQUEST_URI'], '/wp-cron.php') !== false || ( defined('DISABLE_WP_CRON') && DISABLE_WP_CRON ) )
    267267                return;
    268268
     269        _check_cron_for_dst();
     270
    269271        if ( false === $crons = _get_cron_array() )
    270272                return;
    271273
     
    412414        update_option( 'cron', $new_cron );
    413415        return $new_cron;
    414416}
     417
     418/**
     419 * Checks if we need to update the cron times for a DST switch
     420 *
     421 * @since 3.8.0
     422 * @access private
     423 */
     424function _check_cron_for_dst() {
     425        // UTC doesn't have DST
     426        if ( 'UTC' === date_default_timezone_get() )
     427                return;
     428
     429        $yesterday = strtotime( 'yesterday' );
     430
     431        // We're not changing to DST today
     432        if ( date( 'I' ) === date( 'I', $yesterday ) )
     433                return;
     434
     435        // We don't want to change anything until 2am
     436        if ( date( 'G' ) < 2 )
     437                return;
     438
     439        // Don't do anything if we've already changed for DST
     440        $last_dst_change = get_option( 'cron-dst-change', 0 );
     441        if ( $last_dst_change >= time() - DAY_IN_SECONDS )
     442                return;
     443
     444        $offset = HOUR_IN_SECONDS;
     445        // At the start of DST, time goes forward an hour, so the crons need to go back an hour to keep happening at the same time
     446        if ( 1 == date( 'I', $tomorrow ) )
     447                $offset *= -1;
     448
     449        $crons = _get_cron_array();
     450
     451        foreach ( $crons as $timestamp => $cronhooks ) {
     452                foreach ( (array) $cronhooks as $hook => $keys ) {
     453                        foreach ( (array) $keys as $key => $args ) {
     454                                if ( in_array( $args, array( 'daily', 'twicedaily' ) ) ) {
     455                                        // Oh, it's a cron that's affected by DST change
     456                                        unset( $crons[ $timestamp ] );
     457                                        $crons[ $timestamp + $offset ] = $cronhooks;
     458                                        break 2;
     459                                }
     460                        }
     461                }
     462        }
     463
     464        _set_cron_array( $crons );
     465}