mirror of
https://github.com/WordPress/WordPress.git
synced 2024-09-28 15:17:42 +02:00
Clarify that get_the_date()
, get_the_time()
, get_post_time()
and get_post_modified_time()
should return false
when get_post()
is null
.
Adds unit tests. Props GaryJ, SergeyBiryukov, tollmanz. Fixes #28310. Built from https://develop.svn.wordpress.org/trunk@29344 git-svn-id: http://core.svn.wordpress.org/trunk@29122 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
5d102f8e0b
commit
69dbf4f5df
@ -21,7 +21,7 @@ require( ABSPATH . WPINC . '/option.php' );
|
|||||||
* @param string $format Format of the date to return.
|
* @param string $format Format of the date to return.
|
||||||
* @param string $date Date string to convert.
|
* @param string $date Date string to convert.
|
||||||
* @param bool $translate Whether the return date should be translated. Default true.
|
* @param bool $translate Whether the return date should be translated. Default true.
|
||||||
* @return string|int Formatted date string, or Unix timestamp.
|
* @return string|int|bool Formatted date string or Unix timestamp. False if $date is empty.
|
||||||
*/
|
*/
|
||||||
function mysql2date( $format, $date, $translate = true ) {
|
function mysql2date( $format, $date, $translate = true ) {
|
||||||
if ( empty( $date ) )
|
if ( empty( $date ) )
|
||||||
|
@ -1725,11 +1725,15 @@ function the_date( $d = '', $before = '', $after = '', $echo = true ) {
|
|||||||
*
|
*
|
||||||
* @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.
|
* @param int|WP_Post $post Optional. Post ID or WP_Post object. Default current post.
|
||||||
* @return string Date the current post was written.
|
* @return string|bool Date the current post was written. False on failure.
|
||||||
*/
|
*/
|
||||||
function get_the_date( $d = '', $post = null ) {
|
function get_the_date( $d = '', $post = null ) {
|
||||||
$post = get_post( $post );
|
$post = get_post( $post );
|
||||||
|
|
||||||
|
if ( ! $post ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if ( '' == $d ) {
|
if ( '' == $d ) {
|
||||||
$the_date = mysql2date( get_option( 'date_format' ), $post->post_date );
|
$the_date = mysql2date( get_option( 'date_format' ), $post->post_date );
|
||||||
} else {
|
} else {
|
||||||
@ -1839,11 +1843,15 @@ function the_time( $d = '' ) {
|
|||||||
* was written. Either 'G', 'U', or php date format defaults
|
* was written. Either 'G', 'U', or php date format defaults
|
||||||
* to the value specified in the time_format option. Default empty.
|
* to the value specified in the time_format option. Default empty.
|
||||||
* @param int|WP_Post $post WP_Post object or ID. Default is global $post object.
|
* @param int|WP_Post $post WP_Post object or ID. Default is global $post object.
|
||||||
* @return string|int Formatted date string, or Unix timestamp.
|
* @return string|int|bool Formatted date string or Unix timestamp. False on failure.
|
||||||
*/
|
*/
|
||||||
function get_the_time( $d = '', $post = null ) {
|
function get_the_time( $d = '', $post = null ) {
|
||||||
$post = get_post($post);
|
$post = get_post($post);
|
||||||
|
|
||||||
|
if ( ! $post ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if ( '' == $d )
|
if ( '' == $d )
|
||||||
$the_time = get_post_time(get_option('time_format'), false, $post, true);
|
$the_time = get_post_time(get_option('time_format'), false, $post, true);
|
||||||
else
|
else
|
||||||
@ -1873,11 +1881,15 @@ function get_the_time( $d = '', $post = null ) {
|
|||||||
* @param bool $gmt Optional. Whether to retrieve the GMT time. Default false.
|
* @param bool $gmt Optional. Whether to retrieve the GMT time. Default false.
|
||||||
* @param int|WP_Post $post WP_Post object or ID. Default is global $post object.
|
* @param int|WP_Post $post WP_Post object or ID. Default is global $post object.
|
||||||
* @param bool $translate Whether to translate the time string. Default false.
|
* @param bool $translate Whether to translate the time string. Default false.
|
||||||
* @return string|int Formatted date string, or Unix timestamp.
|
* @return string|int|bool Formatted date string or Unix timestamp. False on failure.
|
||||||
*/
|
*/
|
||||||
function get_post_time( $d = 'U', $gmt = false, $post = null, $translate = false ) {
|
function get_post_time( $d = 'U', $gmt = false, $post = null, $translate = false ) {
|
||||||
$post = get_post($post);
|
$post = get_post($post);
|
||||||
|
|
||||||
|
if ( ! $post ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if ( $gmt )
|
if ( $gmt )
|
||||||
$time = $post->post_date_gmt;
|
$time = $post->post_date_gmt;
|
||||||
else
|
else
|
||||||
@ -1951,15 +1963,20 @@ function get_the_modified_time($d = '') {
|
|||||||
*
|
*
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*
|
*
|
||||||
* @param string $d Optional, default is 'U'. Either 'G', 'U', or php date format.
|
* @param string $d Optional. Format to use for retrieving the time the post
|
||||||
* @param bool $gmt Optional, default is false. Whether to return the gmt time.
|
* was modified. Either 'G', 'U', or php date format. Default 'U'.
|
||||||
* @param int|object $post Optional, default is global post object. A post_id or post object
|
* @param bool $gmt Optional. Whether to retrieve the GMT time. Default false.
|
||||||
* @param bool $translate Optional, default is false. Whether to translate the result
|
* @param int|WP_Post $post WP_Post object or ID. Default is global $post object.
|
||||||
* @return string Returns timestamp
|
* @param bool $translate Whether to translate the time string. Default false.
|
||||||
|
* @return string|int|bool Formatted date string or Unix timestamp. False on failure.
|
||||||
*/
|
*/
|
||||||
function get_post_modified_time( $d = 'U', $gmt = false, $post = null, $translate = false ) {
|
function get_post_modified_time( $d = 'U', $gmt = false, $post = null, $translate = false ) {
|
||||||
$post = get_post($post);
|
$post = get_post($post);
|
||||||
|
|
||||||
|
if ( ! $post ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if ( $gmt )
|
if ( $gmt )
|
||||||
$time = $post->post_modified_gmt;
|
$time = $post->post_modified_gmt;
|
||||||
else
|
else
|
||||||
|
Loading…
Reference in New Issue
Block a user