mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-05-20 11:14:28 +00:00
Let get_the_date() accept a post object.
props tanner-m, adamsilverstein, bigdawggi. fixes #13771. git-svn-id: https://develop.svn.wordpress.org/trunk@27380 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -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 );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -865,4 +865,12 @@ class Tests_Post extends WP_UnitTestCase {
|
||||
$this->assertEquals( 9, $after_trash_counts->publish );
|
||||
$this->assertNotEquals( $initial_counts->publish, $after_trash_counts->publish );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 13771
|
||||
*/
|
||||
function test_get_the_date_with_id() {
|
||||
$post_id = $this->factory->post->create( array( 'post_date' => '2014-03-01 16:35:00' ) );
|
||||
$this->assertEquals( 'March 1, 2014', get_the_date( 'F j, Y', $post_id ) );
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user