Make WordPress Core


Ignore:
Timestamp:
04/11/2022 05:01:04 AM (5 years ago)
Author:
peterwilsoncc
Message:

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.

File:
1 edited

Legend:

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

    r53033 r53125  
    511511                $this->assertSame( $expected, get_echo( 'feed_links_extra' ) );
    512512        }
     513
     514        /**
     515         * @ticket 54703
     516         */
     517        public function test_feed_links_extra_should_output_nothing_when_show_comments_feed_filter_returns_false() {
     518                add_filter( 'feed_links_show_comments_feed', '__return_false' );
     519
     520                $this->go_to( get_the_permalink( self::$post_with_comment_id ) );
     521                $this->assertEmpty( get_echo( 'feed_links_extra' ) );
     522        }
     523
     524        /**
     525         * @dataProvider data_feed_links_extra_should_output_nothing_when_post_comments_feed_link_is_falsy
     526         *
     527         * @ticket 54703
     528         *
     529         * @param string $callback The callback to use for the 'post_comments_feed_link' filter.
     530         */
     531        public function test_feed_links_extra_should_output_nothing_when_post_comments_feed_link_is_falsy( $callback ) {
     532                add_filter( 'post_comments_feed_link', $callback );
     533
     534                $this->go_to( get_the_permalink( self::$post_with_comment_id ) );
     535                $this->assertEmpty( get_echo( 'feed_links_extra' ) );
     536        }
     537
     538        /**
     539         * Data provider.
     540         *
     541         * @return array
     542         */
     543        public function data_feed_links_extra_should_output_nothing_when_post_comments_feed_link_is_falsy() {
     544                return array(
     545                        'empty string' => array( 'callback' => '__return_empty_string' ),
     546                        'empty array'  => array( 'callback' => '__return_empty_array' ),
     547                        'zero int'     => array( 'callback' => '__return_zero' ),
     548                        'zero float'   => array( 'callback' => array( $this, 'cb_return_zero_float' ) ),
     549                        'zero string'  => array( 'callback' => array( $this, 'cb_return_zero_string' ) ),
     550                        'null'         => array( 'callback' => '__return_null' ),
     551                        'false'        => array( 'callback' => '__return_false' ),
     552                );
     553        }
     554
     555        /**
     556         * Callback that returns 0.0.
     557         *
     558         * @return float 0.0.
     559         */
     560        public function cb_return_zero_float() {
     561                return 0.0;
     562        }
     563
     564        /**
     565         * Callback that returns '0'.
     566         *
     567         * @return string '0'.
     568         */
     569        public function cb_return_zero_string() {
     570                return '0';
     571        }
     572
     573        /**
     574         * @ticket 54703
     575         */
     576        public function test_feed_links_extra_should_output_the_comments_feed_link_when_show_comments_feed_filter_returns_true() {
     577                add_filter( 'feed_links_show_comments_feed', '__return_true' );
     578
     579                $this->go_to( get_the_permalink( self::$post_with_comment_id ) );
     580                $this->assertNotEmpty( get_echo( 'feed_links_extra' ) );
     581        }
    513582}
Note: See TracChangeset for help on using the changeset viewer.