WordPress.org

Make WordPress Core

Changeset 27380


Ignore:
Timestamp:
03/03/14 17:59:11 (3 years ago)
Author:
nacin
Message:

Let get_the_date() accept a post object.

props tanner-m, adamsilverstein, bigdawggi.
fixes #13771.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/general-template.php

    r27300 r27380  
    14211421 
    14221422/** 
    1423  * Retrieve the date the current post was written. 
     1423 * Retrieve the date on which the post was written. 
    14241424 * 
    14251425 * Unlike the_date() this function will always return the date. 
     
    14281428 * @since 3.0.0 
    14291429 * 
    1430  * @param string $d Optional. PHP date format defaults to the date_format option if not specified. 
     1430 * @param  string      $d    Optional. PHP date format defaults to the date_format option if not specified. 
     1431 * @param  int|WP_Post $post Optional. Post ID or WP_Post object. Default current post. 
    14311432 * @return string Date the current post was written. 
    14321433 */ 
    1433 function get_the_date( $d = '' ) { 
    1434     $post = get_post(); 
    1435  
    1436     if ( '' == $d ) 
     1434function get_the_date( $d = '', $post = null ) { 
     1435    $post = get_post( $post ); 
     1436 
     1437    if ( '' == $d ) { 
    14371438        $the_date = mysql2date( get_option( 'date_format' ), $post->post_date ); 
    1438     else 
     1439    } else { 
    14391440        $the_date = mysql2date( $d, $post->post_date ); 
    1440  
    1441     return apply_filters( 'get_the_date', $the_date, $d ); 
     1441    } 
     1442 
     1443    /** 
     1444     * Filter the date returned from the get_the_date function. 
     1445     * 
     1446     * @since 3.0.0 
     1447     * 
     1448     * @param string      $the_date The formatted date. 
     1449     * @param string      $d        The date format. 
     1450     * @param int|WP_Post $post     The post object or id. 
     1451     */ 
     1452    return apply_filters( 'get_the_date', $the_date, $d, $post ); 
    14421453} 
    14431454 
  • trunk/tests/phpunit/tests/post.php

    r27081 r27380  
    866866        $this->assertNotEquals( $initial_counts->publish, $after_trash_counts->publish ); 
    867867    } 
     868 
     869    /** 
     870     * @ticket 13771 
     871     */ 
     872    function test_get_the_date_with_id() { 
     873        $post_id = $this->factory->post->create( array( 'post_date' => '2014-03-01 16:35:00' ) ); 
     874        $this->assertEquals( 'March 1, 2014', get_the_date( 'F j, Y', $post_id ) ); 
     875    } 
    868876} 
Note: See TracChangeset for help on using the changeset viewer.