Feeds: Use latest comment date for the Last-Modified header of comments feed.

Previously, the `Last-Modified` header of comments feed was using the date/time of the last comment. This behavior was breaking caching and causing feed readers to believe there is no new content even when there might be new posts.

This commit changes this behavior to use the newest date from both `get_lastcommentmodified()` and `get_lastpostmodified()` functions instead of only using the result from `get_lastcommentmodified()`.

Props xiven, mauteri, costdev, audrasjb.
Fixes #47968.


git-svn-id: https://develop.svn.wordpress.org/trunk@53233 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Jb Audras
2022-04-20 12:46:01 +00:00
parent 8ad5aec839
commit 8cb291cbd0
2 changed files with 132 additions and 4 deletions

View File

@@ -413,6 +413,7 @@ class WP {
$headers = array();
$status = null;
$exit_required = false;
$date_format = 'D, d M Y H:i:s';
if ( is_user_logged_in() ) {
$headers = array_merge( $headers, wp_get_nocache_headers() );
@@ -420,7 +421,7 @@ class WP {
// Unmoderated comments are only visible for 10 minutes via the moderation hash.
$expires = 10 * MINUTE_IN_SECONDS;
$headers['Expires'] = gmdate( 'D, d M Y H:i:s', time() + $expires );
$headers['Expires'] = gmdate( $date_format, time() + $expires );
$headers['Cache-Control'] = sprintf(
'max-age=%d, must-revalidate',
$expires
@@ -459,13 +460,19 @@ class WP {
)
)
) {
$wp_last_modified = mysql2date( 'D, d M Y H:i:s', get_lastcommentmodified( 'GMT' ), false );
$wp_last_modified_post = mysql2date( $date_format, get_lastpostmodified( 'GMT' ), false );
$wp_last_modified_comment = mysql2date( $date_format, get_lastcommentmodified( 'GMT' ), false );
if ( strtotime( $wp_last_modified_post ) > strtotime( $wp_last_modified_comment ) ) {
$wp_last_modified = $wp_last_modified_post;
} else {
$wp_last_modified = $wp_last_modified_comment;
}
} else {
$wp_last_modified = mysql2date( 'D, d M Y H:i:s', get_lastpostmodified( 'GMT' ), false );
$wp_last_modified = mysql2date( $date_format, get_lastpostmodified( 'GMT' ), false );
}
if ( ! $wp_last_modified ) {
$wp_last_modified = gmdate( 'D, d M Y H:i:s' );
$wp_last_modified = gmdate( $date_format );
}
$wp_last_modified .= ' GMT';