WordPress.org

Make WordPress Core

Changeset 14487


Ignore:
Timestamp:
05/06/10 20:40:29 (4 years ago)
Author:
westi
Message:

Improve cross DST future post publishing behaviour to try and publish at the correct time if we have PHP5 timezone support available to help. Fixes #9285 props technosailor.

Location:
trunk/wp-includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/formatting.php

    r14428 r14487  
    15541554 * Requires and returns a date in the Y-m-d H:i:s format. Simply subtracts the 
    15551555 * value of the 'gmt_offset' option. Return format can be overridden using the 
    1556  * $format parameter 
     1556 * $format parameter. If PHP5 is supported, the function uses the DateTime and 
     1557 * DateTimeZone objects to respect time zone differences in DST. 
    15571558 * 
    15581559 * @since 1.2.0 
     
    15651566function get_gmt_from_date($string, $format = 'Y-m-d H:i:s') { 
    15661567    preg_match('#([0-9]{1,4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})#', $string, $matches); 
    1567     $string_time = gmmktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1]); 
    1568     $string_gmt = gmdate($format, $string_time - get_option('gmt_offset') * 3600); 
     1568    $tz = get_option('timezone_string'); 
     1569    if( class_exists('DateTime') && $tz ) { 
     1570        //PHP5 
     1571        date_default_timezone_set( $tz ); 
     1572        $datetime = new DateTime( $string ); 
     1573        $datetime->setTimezone( new DateTimeZone('UTC') ); 
     1574        $offset = $datetime->getOffset(); 
     1575        $datetime->modify( '+' . $offset / 3600 . ' hours'); 
     1576        $string_gmt = gmdate($format, $datetime->format('U')); 
     1577 
     1578        date_default_timezone_set('UTC'); 
     1579    } 
     1580    else { 
     1581        //PHP4 
     1582        $string_time = gmmktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1]); 
     1583        $string_gmt = gmdate($format, $string_time - get_option('gmt_offset') * 3600); 
     1584    } 
    15691585    return $string_gmt; 
    15701586} 
  • trunk/wp-includes/post.php

    r14478 r14487  
    41394139function _future_post_hook( $deprecated = '', $post ) { 
    41404140    wp_clear_scheduled_hook( 'publish_future_post', array( $post->ID ) ); 
    4141     wp_schedule_single_event( strtotime( $post->post_date_gmt. ' GMT' ), 'publish_future_post', array( $post->ID ) ); 
     4141    wp_schedule_single_event( get_gmt_from_date( $post->post_date ) . ' GMT', 'publish_future_post', array( $post->ID ) ); 
    41424142} 
    41434143 
Note: See TracChangeset for help on using the changeset viewer.