From f1bcaeb35f143f246a3dece58ed34f9b127e83a1 Mon Sep 17 00:00:00 2001 From: Andrew Nacin Date: Mon, 3 Mar 2014 18:00:14 +0000 Subject: [PATCH] Let get_the_date() accept a post object. props tanner-m, adamsilverstein, bigdawggi. fixes #13771. Built from https://develop.svn.wordpress.org/trunk@27380 git-svn-id: http://core.svn.wordpress.org/trunk@27229 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/general-template.php | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/wp-includes/general-template.php b/wp-includes/general-template.php index 98898c3f99..18ffa73a5a 100644 --- a/wp-includes/general-template.php +++ b/wp-includes/general-template.php @@ -1420,25 +1420,36 @@ function the_date( $d = '', $before = '', $after = '', $echo = true ) { } /** - * Retrieve the date the current post was written. + * Retrieve the date on which the post was written. * * Unlike the_date() this function will always return the date. * Modify output with 'get_the_date' filter. * * @since 3.0.0 * - * @param string $d Optional. PHP date format defaults to the date_format option if not specified. + * @param string $d Optional. PHP date format defaults to the date_format option if not specified. + * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default current post. * @return string Date the current post was written. */ -function get_the_date( $d = '' ) { - $post = get_post(); +function get_the_date( $d = '', $post = null ) { + $post = get_post( $post ); - if ( '' == $d ) + if ( '' == $d ) { $the_date = mysql2date( get_option( 'date_format' ), $post->post_date ); - else + } else { $the_date = mysql2date( $d, $post->post_date ); + } - return apply_filters( 'get_the_date', $the_date, $d ); + /** + * Filter the date returned from the get_the_date function. + * + * @since 3.0.0 + * + * @param string $the_date The formatted date. + * @param string $d The date format. + * @param int|WP_Post $post The post object or id. + */ + return apply_filters( 'get_the_date', $the_date, $d, $post ); } /**