From 943e956379dd935ad6b401669a4c76526172f594 Mon Sep 17 00:00:00 2001 From: audrasjb Date: Wed, 20 Apr 2022 12:47:11 +0000 Subject: [PATCH] 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. Built from https://develop.svn.wordpress.org/trunk@53233 git-svn-id: http://core.svn.wordpress.org/trunk@52822 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/class-wp.php | 15 +++++++++++---- wp-includes/version.php | 2 +- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/wp-includes/class-wp.php b/wp-includes/class-wp.php index 23af2fff87..ca9399e4e5 100644 --- a/wp-includes/class-wp.php +++ b/wp-includes/class-wp.php @@ -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'; diff --git a/wp-includes/version.php b/wp-includes/version.php index 8c793f0caf..a736f25831 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.0-beta2-53232'; +$wp_version = '6.0-beta2-53233'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.