Make WordPress Core


Ignore:
Timestamp:
09/14/2022 05:12:20 PM (2 years ago)
Author:
SergeyBiryukov
Message:

Feeds: Add a set of fine-grained filters to disable the different types of feed links separately.

The previously available set of filters in the feed_links() function to enable or disable display of various feed links was quite limited:

  • feed_links_show_posts_feed to control the main feed
  • feed_links_show_comments_feed to control both the global comments feed and the comment feed for singular posts.

In order to disable the other feeds (post type archive, category, tag, custom taxonomy, author archive, search results), one would have to unhook feed_links_extra() from wp_head, but that would completely remove all of those feeds, as well as the single post comments feed.

To allow for more flexibility, this commit introduces a full set of filters in the feed_links_extra() function to control each one of the feeds independently, including a way to enable/disable the single post comments feed when the global comments feed is disabled/enabled:

  • feed_links_extra_show_post_comments_feed
  • feed_links_extra_show_post_type_archive_feed
  • feed_links_extra_show_category_feed
  • feed_links_extra_show_tag_feed
  • feed_links_extra_show_tax_feed
  • feed_links_extra_show_author_feed
  • feed_links_extra_show_search_feed

All of them default to true, except for feed_links_extra_show_post_comments_feed which defaults to the result of feed_links_show_comments_feed to ensure backward compatibility.

Follow-up to [33838], [33839], [53125].

Props lopo, mukesh27, audrasjb, SergeyBiryukov.
Fixes #55904.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/general/feedLinksExtra.php

    r53125 r54161  
    580580        $this->assertNotEmpty( get_echo( 'feed_links_extra' ) );
    581581    }
     582
     583    /**
     584     * @dataProvider data_feed_links_extra_should_output_nothing_when_filters_return_false
     585     *
     586     * @ticket 55904
     587     *
     588     * @param string $type   The name of the test class property containing the object ID.
     589     * @param string $filter The name of the filter to set to false.
     590     */
     591    public function test_feed_links_extra_should_output_nothing_when_filters_return_false( $type, $filter ) {
     592        $permalink = $this->helper_get_the_permalink( $type );
     593        $this->go_to( $permalink );
     594
     595        add_filter( $filter, '__return_false' );
     596
     597        $this->assertEmpty( get_echo( 'feed_links_extra' ) );
     598    }
     599
     600    /**
     601     * Data provider.
     602     *
     603     * @return array
     604     */
     605    public function data_feed_links_extra_should_output_nothing_when_filters_return_false() {
     606        return array(
     607            'a post with a comment' => array(
     608                'type'   => 'post_with_comment',
     609                'filter' => 'feed_links_extra_show_post_comments_feed',
     610            ),
     611            'a custom post type'    => array(
     612                'type'   => 'post_type',
     613                'filter' => 'feed_links_extra_show_post_type_archive_feed',
     614            ),
     615            'a category'            => array(
     616                'type'   => 'category',
     617                'filter' => 'feed_links_extra_show_category_feed',
     618            ),
     619            'a tag'                 => array(
     620                'type'   => 'tag',
     621                'filter' => 'feed_links_extra_show_tag_feed',
     622            ),
     623            'a taxonomy'            => array(
     624                'type'   => 'tax',
     625                'filter' => 'feed_links_extra_show_tax_feed',
     626            ),
     627            'an author'             => array(
     628                'type'   => 'author',
     629                'filter' => 'feed_links_extra_show_author_feed',
     630            ),
     631            'search results'        => array(
     632                'type'   => 'search',
     633                'filter' => 'feed_links_extra_show_search_feed',
     634            ),
     635        );
     636    }
    582637}
Note: See TracChangeset for help on using the changeset viewer.