From b90d225de1986321c0c0aca29f8d943e0ef7a8cd Mon Sep 17 00:00:00 2001 From: Peter Wilson Date: Mon, 11 Apr 2022 05:03:03 +0000 Subject: [PATCH] Feeds: Remove comment feed HTML headers when empty. Remove the `link[rel=alternate]` element from the HTML header when the comment feeds are disabled. Previously the HTML element was output with an empty `href` attribute. The element is removed if `get_post_comments_feed_link()` returns an empty string or the feed is disabled via the `feed_links_show_comments_feed` filter. Props barryceelen, audrasjb, costdev, rachelbaker, Boniu91. Fixes #54703. Built from https://develop.svn.wordpress.org/trunk@53125 git-svn-id: http://core.svn.wordpress.org/trunk@52714 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/general-template.php | 13 ++++++++++--- wp-includes/version.php | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/wp-includes/general-template.php b/wp-includes/general-template.php index edccff2807..f09c54ee96 100644 --- a/wp-includes/general-template.php +++ b/wp-includes/general-template.php @@ -3153,9 +3153,16 @@ function feed_links_extra( $args = array() ) { $id = 0; $post = get_post( $id ); - if ( comments_open() || pings_open() || $post->comment_count > 0 ) { - $title = sprintf( $args['singletitle'], get_bloginfo( 'name' ), $args['separator'], the_title_attribute( array( 'echo' => false ) ) ); - $href = get_post_comments_feed_link( $post->ID ); + /** This filter is documented in wp-includes/general-template.php */ + $show_comments_feed = apply_filters( 'feed_links_show_comments_feed', true ); + + if ( $show_comments_feed && ( comments_open() || pings_open() || $post->comment_count > 0 ) ) { + $title = sprintf( $args['singletitle'], get_bloginfo( 'name' ), $args['separator'], the_title_attribute( array( 'echo' => false ) ) ); + $feed_link = get_post_comments_feed_link( $post->ID ); + + if ( $feed_link ) { + $href = $feed_link; + } } } elseif ( is_post_type_archive() ) { $post_type = get_query_var( 'post_type' ); diff --git a/wp-includes/version.php b/wp-includes/version.php index 52c3fa9342..3bc6da94e0 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.0-alpha-53124'; +$wp_version = '6.0-alpha-53125'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.