From afe975d75427899d024208b3cc34399b9cab7162 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Tue, 20 Oct 2015 06:08:25 +0000 Subject: [PATCH] Formatting: allow date strings to be passed to `get_gmt_from_date()`, instead of requiring `'Y-m-d H:i:s'`. Adds unit tests. Props pbearne. Fixes #34279. Built from https://develop.svn.wordpress.org/trunk@35284 git-svn-id: http://core.svn.wordpress.org/trunk@35250 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/formatting.php | 20 +++++++++++++------- wp-includes/version.php | 2 +- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/wp-includes/formatting.php b/wp-includes/formatting.php index 8bf9980089..65ef3e36d2 100644 --- a/wp-includes/formatting.php +++ b/wp-includes/formatting.php @@ -611,7 +611,7 @@ function get_html_split_regex() { . ')*+' // Loop possessively. . '(?:]]>)?'; // End of comment. If not found, match all input. - $escaped = + $escaped = '(?=' // Is the element escaped? . '!--' . '|' @@ -2587,13 +2587,19 @@ function get_gmt_from_date( $string, $format = 'Y-m-d H:i:s' ) { $tz = get_option( 'timezone_string' ); if ( $tz ) { $datetime = date_create( $string, new DateTimeZone( $tz ) ); - if ( ! $datetime ) + if ( ! $datetime ) { return gmdate( $format, 0 ); + } $datetime->setTimezone( new DateTimeZone( 'UTC' ) ); $string_gmt = $datetime->format( $format ); } else { - if ( ! 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 ) ) - return gmdate( $format, 0 ); + if ( ! 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 ) ) { + $datetime = strtotime( $string ); + if ( false === $datetime ) { + return gmdate( $format, 0 ); + } + return gmdate( $format, $datetime ); + } $string_time = gmmktime( $matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1] ); $string_gmt = gmdate( $format, $string_time - get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ); } @@ -3876,10 +3882,10 @@ function sanitize_option( $option, $value ) { * * This is similar to `array_walk_recursive()` but acts upon objects too. * - * @since 4.4.0 - * + * @since 4.4.0 + * * @param mixed $value The array, object, or scalar. - * @param callable $function The function to map onto $value. + * @param callable $callback The function to map onto $value. * @return The value with the callback applied to all non-arrays and non-objects inside it. */ function map_deep( $value, $callback ) { diff --git a/wp-includes/version.php b/wp-includes/version.php index e6349081a6..fbf9b6131a 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.4-alpha-35283'; +$wp_version = '4.4-alpha-35284'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.