Make WordPress Core

Changeset 52031


Ignore:
Timestamp:
11/07/2021 11:03:47 PM (3 years ago)
Author:
joedolson
Message:

Widgets: Add filter to disable RSS widget icon.

Add a filter that disables output of the icon on RSS feed widgets. Improves accessibility by providing a path to prevent duplicate or invisible links.

Props sabernhardt, Boniu91.
Fixes #52224.

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-content/themes/twentyseventeen/rtl.css

    r46586 r52031  
    228228.widget ul {
    229229    margin: 0;
     230}
     231
     232.widget_rss .widget-title .rsswidget:first-child:not(.rss-widget-title) {
     233    float: left;
    230234}
    231235
  • trunk/src/wp-content/themes/twentyseventeen/style.css

    r51808 r52031  
    26632663/* RSS Widget */
    26642664
    2665 .widget_rss .widget-title .rsswidget:first-child {
     2665.widget_rss .widget-title .rsswidget:first-child:not(.rss-widget-title) {
    26662666    float: right;
    26672667}
  • trunk/src/wp-content/themes/twentytwenty/style-rtl.css

    r52023 r52031  
    42874287/* Widget: RSS ------------------------------- */
    42884288
    4289 .widget_rss .widget-title a.rsswidget:first-of-type {
     4289.widget_rss .widget-title a.rsswidget:first-of-type:not(.rss-widget-title) {
    42904290    display: none;
    42914291}
  • trunk/src/wp-content/themes/twentytwenty/style.css

    r52023 r52031  
    43214321/* Widget: RSS ------------------------------- */
    43224322
    4323 .widget_rss .widget-title a.rsswidget:first-of-type {
     4323.widget_rss .widget-title a.rsswidget:first-of-type:not(.rss-widget-title) {
    43244324    display: none;
    43254325}
  • trunk/src/wp-includes/widgets/class-wp-widget-rss.php

    r51967 r52031  
    8787        $title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
    8888
    89         $url  = strip_tags( $url );
    90         $icon = includes_url( 'images/rss.png' );
    9189        if ( $title ) {
    92             $title = '<a class="rsswidget" href="' . esc_url( $url ) . '"><img class="rss-widget-icon" style="border:0" width="14" height="14" src="' . esc_url( $icon ) . '" alt="RSS" /></a> <a class="rsswidget" href="' . esc_url( $link ) . '">' . esc_html( $title ) . '</a>';
     90            $feed_link = '';
     91            $feed_url  = strip_tags( $url );
     92            $feed_icon = includes_url( 'images/rss.png' );
     93            $feed_link = sprintf(
     94                '<a class="rsswidget rss-widget-feed" href="%1$s"><img class="rss-widget-icon" style="border:0" width="14" height="14" src="%2$s" alt="%3$s"%4$s /></a> ',
     95                esc_url( $feed_url ),
     96                esc_url( $feed_icon ),
     97                esc_attr__( 'RSS' ),
     98                ( wp_lazy_loading_enabled( 'img', 'rss_widget_feed_icon' ) ? ' loading="lazy"' : '' )
     99            );
     100
     101            /**
     102             * Filters the classic RSS widget's feed icon link.
     103             *
     104             * Themes can remove the icon link by using `add_filter( 'rss_widget_feed_link', '__return_false' );`.
     105             *
     106             * @since 5.9.0
     107             *
     108             * @param string $feed_link HTML for link to RSS feed.
     109             * @param array  $instance  Array of settings for the current widget.
     110             */
     111            $feed_link = apply_filters( 'rss_widget_feed_link', $feed_link, $instance );
     112
     113            $title = $feed_link . '<a class="rsswidget rss-widget-title" href="' . esc_url( $link ) . '">' . esc_html( $title ) . '</a>';
    93114        }
    94115
  • trunk/tests/phpunit/tests/rest-api/rest-widgets-controller.php

    r52016 r52031  
    395395                    'id_base'  => 'rss',
    396396                    'sidebar'  => 'sidebar-1',
    397                     'rendered' => '<a class="rsswidget" href="https://wordpress.org/news/feed"><img class="rss-widget-icon" style="border:0" width="14" height="14" src="http://example.org/wp-includes/images/rss.png" alt="RSS" /></a> <a class="rsswidget" href="https://wordpress.org/news">RSS test</a><ul><li><a class=\'rsswidget\' href=\'https://wordpress.org/news/2020/12/introducing-learn-wordpress/\'>Introducing Learn WordPress</a></li><li><a class=\'rsswidget\' href=\'https://wordpress.org/news/2020/12/simone/\'>WordPress 5.6 “Simone”</a></li><li><a class=\'rsswidget\' href=\'https://wordpress.org/news/2020/12/state-of-the-word-2020/\'>State of the Word 2020</a></li><li><a class=\'rsswidget\' href=\'https://wordpress.org/news/2020/12/the-month-in-wordpress-november-2020/\'>The Month in WordPress: November 2020</a></li><li><a class=\'rsswidget\' href=\'https://wordpress.org/news/2020/12/wordpress-5-6-release-candidate-2/\'>WordPress 5.6 Release Candidate 2</a></li><li><a class=\'rsswidget\' href=\'https://wordpress.org/news/2020/11/wordpress-5-6-release-candidate/\'>WordPress 5.6 Release Candidate</a></li><li><a class=\'rsswidget\' href=\'https://wordpress.org/news/2020/11/wordpress-5-6-beta-4/\'>WordPress 5.6 Beta 4</a></li><li><a class=\'rsswidget\' href=\'https://wordpress.org/news/2020/11/wordpress-5-6-beta-3/\'>WordPress 5.6 Beta 3</a></li><li><a class=\'rsswidget\' href=\'https://wordpress.org/news/2020/11/the-month-in-wordpress-october-2020/\'>The Month in WordPress: October 2020</a></li><li><a class=\'rsswidget\' href=\'https://wordpress.org/news/2020/10/wordpress-5-5-3-maintenance-release/\'>WordPress 5.5.3 Maintenance Release</a></li></ul>',
     397                    'rendered' => '<a class="rsswidget rss-widget-feed" href="https://wordpress.org/news/feed"><img class="rss-widget-icon" style="border:0" width="14" height="14" src="http://example.org/wp-includes/images/rss.png" alt="RSS" loading="lazy" /></a> <a class="rsswidget rss-widget-title" href="https://wordpress.org/news">RSS test</a><ul><li><a class=\'rsswidget\' href=\'https://wordpress.org/news/2020/12/introducing-learn-wordpress/\'>Introducing Learn WordPress</a></li><li><a class=\'rsswidget\' href=\'https://wordpress.org/news/2020/12/simone/\'>WordPress 5.6 “Simone”</a></li><li><a class=\'rsswidget\' href=\'https://wordpress.org/news/2020/12/state-of-the-word-2020/\'>State of the Word 2020</a></li><li><a class=\'rsswidget\' href=\'https://wordpress.org/news/2020/12/the-month-in-wordpress-november-2020/\'>The Month in WordPress: November 2020</a></li><li><a class=\'rsswidget\' href=\'https://wordpress.org/news/2020/12/wordpress-5-6-release-candidate-2/\'>WordPress 5.6 Release Candidate 2</a></li><li><a class=\'rsswidget\' href=\'https://wordpress.org/news/2020/11/wordpress-5-6-release-candidate/\'>WordPress 5.6 Release Candidate</a></li><li><a class=\'rsswidget\' href=\'https://wordpress.org/news/2020/11/wordpress-5-6-beta-4/\'>WordPress 5.6 Beta 4</a></li><li><a class=\'rsswidget\' href=\'https://wordpress.org/news/2020/11/wordpress-5-6-beta-3/\'>WordPress 5.6 Beta 3</a></li><li><a class=\'rsswidget\' href=\'https://wordpress.org/news/2020/11/the-month-in-wordpress-october-2020/\'>The Month in WordPress: October 2020</a></li><li><a class=\'rsswidget\' href=\'https://wordpress.org/news/2020/10/wordpress-5-5-3-maintenance-release/\'>WordPress 5.5.3 Maintenance Release</a></li></ul>',
    398398                ),
    399399                array(
  • trunk/tests/phpunit/tests/widgets/wpWidgetRss.php

    r51493 r52031  
    9595            'when url is given' => array(
    9696                'url' => 'https://wordpress.org/news/feed/',
    97                 '<section id="widget_rss-5" class="widget widget_rss"><h2><a class="rsswidget" href="https://wordpress.org/news/feed/">',
     97                '<section id="widget_rss-5" class="widget widget_rss"><h2><a class="rsswidget rss-widget-feed" href="https://wordpress.org/news/feed/">',
    9898            ),
    9999        );
Note: See TracChangeset for help on using the changeset viewer.