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.

git-svn-id: https://develop.svn.wordpress.org/trunk@22435 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Andrew Nacin 2012-11-07 20:07:41 +00:00
parent b21172a14a
commit e25ee1e3e6
1 changed files with 7 additions and 1 deletions

View File

@ -1892,10 +1892,16 @@ function _wp_iso_convert( $match ) {
*/
function get_gmt_from_date($string, $format = 'Y-m-d H:i:s') {
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);
if ( ! $matches )
return date( $format, 0 );
$tz = get_option('timezone_string');
if ( $tz ) {
date_default_timezone_set( $tz );
$datetime = new DateTime( $string );
$datetime = date_create( $string );
if ( ! $datetime )
return date( $format, 0 );
$datetime->setTimezone( new DateTimeZone('UTC') );
$offset = $datetime->getOffset();
$datetime->modify( '+' . $offset / HOUR_IN_SECONDS . ' hours');