Make WordPress Core

Changeset 22435


Ignore:
Timestamp:
11/07/2012 08:07:41 PM (12 years ago)
Author:
nacin
Message:

Avoid an uncaught exception in get_gmt_from_date(). The return value is imperfect - date( $format, 0 ) - but better than a fatal error. props wonderboymusic. fixes #20942.

File:
1 edited

Legend:

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

    r22401 r22435  
    18931893function get_gmt_from_date($string, $format = 'Y-m-d H:i:s') {
    18941894    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);
     1895    if ( ! $matches )
     1896        return date( $format, 0 );
     1897
    18951898    $tz = get_option('timezone_string');
    18961899    if ( $tz ) {
    18971900        date_default_timezone_set( $tz );
    1898         $datetime = new DateTime( $string );
     1901        $datetime = date_create( $string );
     1902        if ( ! $datetime )
     1903            return date( $format, 0 );
     1904
    18991905        $datetime->setTimezone( new DateTimeZone('UTC') );
    19001906        $offset = $datetime->getOffset();
Note: See TracChangeset for help on using the changeset viewer.