Posts, Post Types: Pass the post type to get_lastpostdate() in get_lastpostmodified().

This ensures that the correct values are being compared when retrieving the result for custom post types.

Additionally, pass the `$post_type` parameter to `get_lastpostdate` and `get_lastpostmodified` filters.

Props mikaumoto, munyagu, donmhico, johnbillion, SergeyBiryukov.
Fixes #47777.
Built from https://develop.svn.wordpress.org/trunk@48631


git-svn-id: http://core.svn.wordpress.org/trunk@48393 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2020-07-27 02:18:05 +00:00
parent f547eb6174
commit 4c0a764adc
2 changed files with 14 additions and 7 deletions

View File

@ -6620,16 +6620,20 @@ function get_posts_by_author_sql( $post_type, $full = true, $post_author = null,
* @return string The date of the last post, or false on failure.
*/
function get_lastpostdate( $timezone = 'server', $post_type = 'any' ) {
$date = _get_last_post_time( $timezone, 'date', $post_type );
/**
* Filters the most recent time that a post on the site was published.
*
* @since 2.3.0
* @since 5.5.0 Added the `$post_type` parameter.
*
* @param string|false $date Date the last post was published. False on failure.
* @param string $timezone Location to use for getting the post published date.
* See get_lastpostdate() for accepted `$timezone` values.
* @param string|false $date Date the last post was published. False on failure.
* @param string $timezone Location to use for getting the post published date.
* See get_lastpostdate() for accepted `$timezone` values.
* @param string $post_type The post type to check.
*/
return apply_filters( 'get_lastpostdate', _get_last_post_time( $timezone, 'date', $post_type ), $timezone );
return apply_filters( 'get_lastpostdate', $date, $timezone, $post_type );
}
/**
@ -6661,13 +6665,14 @@ function get_lastpostmodified( $timezone = 'server', $post_type = 'any' ) {
* @param string $post_type The post type to check.
*/
$lastpostmodified = apply_filters( 'pre_get_lastpostmodified', false, $timezone, $post_type );
if ( false !== $lastpostmodified ) {
return $lastpostmodified;
}
$lastpostmodified = _get_last_post_time( $timezone, 'modified', $post_type );
$lastpostdate = get_lastpostdate( $timezone, $post_type );
$lastpostdate = get_lastpostdate( $timezone );
if ( $lastpostdate > $lastpostmodified ) {
$lastpostmodified = $lastpostdate;
}
@ -6676,13 +6681,15 @@ function get_lastpostmodified( $timezone = 'server', $post_type = 'any' ) {
* Filters the most recent time that a post was modified.
*
* @since 2.3.0
* @since 5.5.0 Added the `$post_type` parameter.
*
* @param string|false $lastpostmodified The most recent time that a post was modified, in 'Y-m-d H:i:s' format.
* False on failure.
* @param string $timezone Location to use for getting the post modified date.
* See get_lastpostdate() for accepted `$timezone` values.
* @param string $post_type The post type to check.
*/
return apply_filters( 'get_lastpostmodified', $lastpostmodified, $timezone );
return apply_filters( 'get_lastpostmodified', $lastpostmodified, $timezone, $post_type );
}
/**

View File

@ -13,7 +13,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.5-beta3-48630';
$wp_version = '5.5-beta3-48631';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.