From d3abb209e1ebefb1996afa1c1b3877ace20e2389 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Mon, 31 Aug 2020 18:30:05 +0000 Subject: [PATCH] Date/Time: In `get_the_date()` and related functions, pass the original, unmodified `$format` value to the filters. Additionally, simplify the `$format` argument checks for consistency with similar checks in `get_the_modified_date()` and `get_the_modified_time()`. Follow-up to [48912]. Props Rarst. See #51184. Built from https://develop.svn.wordpress.org/trunk@48918 git-svn-id: http://core.svn.wordpress.org/trunk@48680 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/comment-template.php | 12 ++++-------- wp-includes/general-template.php | 24 ++++++++++-------------- wp-includes/version.php | 2 +- 3 files changed, 15 insertions(+), 23 deletions(-) diff --git a/wp-includes/comment-template.php b/wp-includes/comment-template.php index a048d3870c..b7c644db1e 100644 --- a/wp-includes/comment-template.php +++ b/wp-includes/comment-template.php @@ -552,11 +552,9 @@ function get_comment_class( $class = '', $comment_id = null, $post_id = null ) { function get_comment_date( $format = '', $comment_ID = 0 ) { $comment = get_comment( $comment_ID ); - if ( ! is_string( $format ) || '' === $format ) { - $format = get_option( 'date_format' ); - } + $_format = ! empty( $format ) ? $format : get_option( 'date_format' ); - $date = mysql2date( $format, $comment->comment_date ); + $date = mysql2date( $_format, $comment->comment_date ); /** * Filters the returned comment date. @@ -1046,11 +1044,9 @@ function get_comment_time( $format = '', $gmt = false, $translate = true ) { $comment_date = $gmt ? $comment->comment_date_gmt : $comment->comment_date; - if ( ! is_string( $format ) || '' === $format ) { - $format = get_option( 'time_format' ); - } + $_format = ! empty( $format ) ? $format : get_option( 'time_format' ); - $date = mysql2date( $format, $comment_date, $translate ); + $date = mysql2date( $_format, $comment_date, $translate ); /** * Filters the returned comment time. diff --git a/wp-includes/general-template.php b/wp-includes/general-template.php index 89748f1968..ec9eba3e93 100644 --- a/wp-includes/general-template.php +++ b/wp-includes/general-template.php @@ -2525,11 +2525,9 @@ function get_the_date( $format = '', $post = null ) { return false; } - if ( ! is_string( $format ) || '' === $format ) { - $format = get_option( 'date_format' ); - } + $_format = ! empty( $format ) ? $format : get_option( 'date_format' ); - $the_date = get_post_time( $format, false, $post, true ); + $the_date = get_post_time( $_format, false, $post, true ); /** * Filters the date a post was published. @@ -2595,10 +2593,10 @@ function get_the_modified_date( $format = '', $post = null ) { if ( ! $post ) { // For backward compatibility, failures go through the filter below. $the_time = false; - } elseif ( empty( $format ) ) { - $the_time = get_post_modified_time( get_option( 'date_format' ), false, $post, true ); } else { - $the_time = get_post_modified_time( $format, false, $post, true ); + $_format = ! empty( $format ) ? $format : get_option( 'date_format' ); + + $the_time = get_post_modified_time( $_format, false, $post, true ); } /** @@ -2654,11 +2652,9 @@ function get_the_time( $format = '', $post = null ) { return false; } - if ( ! is_string( $format ) || '' === $format ) { - $format = get_option( 'time_format' ); - } + $_format = ! empty( $format ) ? $format : get_option( 'time_format' ); - $the_time = get_post_time( $format, false, $post, true ); + $the_time = get_post_time( $_format, false, $post, true ); /** * Filters the time a post was written. @@ -2843,10 +2839,10 @@ function get_the_modified_time( $format = '', $post = null ) { if ( ! $post ) { // For backward compatibility, failures go through the filter below. $the_time = false; - } elseif ( empty( $format ) ) { - $the_time = get_post_modified_time( get_option( 'time_format' ), false, $post, true ); } else { - $the_time = get_post_modified_time( $format, false, $post, true ); + $_format = ! empty( $format ) ? $format : get_option( 'time_format' ); + + $the_time = get_post_modified_time( $_format, false, $post, true ); } /** diff --git a/wp-includes/version.php b/wp-includes/version.php index 121cae7d6d..ef97adc4cb 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.6-alpha-48913'; +$wp_version = '5.6-alpha-48918'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.