Make WordPress Core

Ticket #13771: 13771.3.diff

File 13771.3.diff, 2.3 KB (added by adamsilverstein, 11 years ago)
  • src/wp-includes/general-template.php

     
    14201420}
    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.
    14261426 * Modify output with 'get_the_date' filter.
    14271427 *
    14281428 * @since 3.0.0
    14291429 *
    1430  * @param string $d Optional. PHP date format defaults to the date_format option if not specified.
    1431  * @return string Date the current post was written.
     1430 * @param  string      $d    Optional. PHP date format defaults to the date_format option if not specified.
     1431 * @param  int|WP_Post $post Optional. WP_Post object or ID. Default is global $post object.
     1432 * @return string      Date the current post was written.
    14321433 */
    1433 function get_the_date( $d = '' ) {
    1434         $post = get_post();
     1434function get_the_date( $d = '', $post = 0 ) {
     1435        $post = get_post( $post );
    14351436
    14361437        if ( '' == $d )
    14371438                $the_date = mysql2date( get_option( 'date_format' ), $post->post_date );
    14381439        else
    14391440                $the_date = mysql2date( $d, $post->post_date );
    14401441
    1441         return apply_filters( 'get_the_date', $the_date, $d );
     1442        /**
     1443         * Filter the date returned from the get_the_date function.
     1444         *
     1445         * @since 3.0.0
     1446         *
     1447         * @param string      $the_date The formatted date.
     1448         * @param string      $d        The date format.
     1449         * @param int|WP_Post $post     The post object or id.
     1450         */
     1451        return apply_filters( 'get_the_date', $the_date, $d, $post );
    14421452}
    14431453
    14441454/**
  • tests/phpunit/tests/post.php

     
    865865                $this->assertEquals( 9, $after_trash_counts->publish );
    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_data = array(
     874                        'post_status'  => 'public',
     875                        'post_content' => rand_str(),
     876                        'post_title'   => 'Post test',
     877                        'post_date'    => '2014-03-01 16:35:00',
     878                );
     879                $insert_post_id = wp_insert_post( $post_data );
     880
     881                $this->assertEquals( 'March 1, 2014', get_the_date( 'F j, Y', $insert_post_id ) );
     882        }
    868883}