From 2ce222c92b36b8061caca5669ee143370562483f Mon Sep 17 00:00:00 2001 From: Joe Dolson Date: Sun, 7 Nov 2021 23:03:47 +0000 Subject: [PATCH] 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. git-svn-id: https://develop.svn.wordpress.org/trunk@52031 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-content/themes/twentyseventeen/rtl.css | 4 +++ .../themes/twentyseventeen/style.css | 2 +- .../themes/twentytwenty/style-rtl.css | 2 +- src/wp-content/themes/twentytwenty/style.css | 2 +- .../widgets/class-wp-widget-rss.php | 27 ++++++++++++++++--- .../rest-api/rest-widgets-controller.php | 2 +- tests/phpunit/tests/widgets/wpWidgetRss.php | 2 +- 7 files changed, 33 insertions(+), 8 deletions(-) diff --git a/src/wp-content/themes/twentyseventeen/rtl.css b/src/wp-content/themes/twentyseventeen/rtl.css index 1c5e4c7adf..f91e2a6ded 100644 --- a/src/wp-content/themes/twentyseventeen/rtl.css +++ b/src/wp-content/themes/twentyseventeen/rtl.css @@ -229,6 +229,10 @@ input[type="checkbox"] { margin: 0; } +.widget_rss .widget-title .rsswidget:first-child:not(.rss-widget-title) { + float: left; +} + .search-form .search-submit { left: 3px; right: auto; diff --git a/src/wp-content/themes/twentyseventeen/style.css b/src/wp-content/themes/twentyseventeen/style.css index b3621b79e3..be1c214696 100644 --- a/src/wp-content/themes/twentyseventeen/style.css +++ b/src/wp-content/themes/twentyseventeen/style.css @@ -2662,7 +2662,7 @@ h2.widget-title { /* RSS Widget */ -.widget_rss .widget-title .rsswidget:first-child { +.widget_rss .widget-title .rsswidget:first-child:not(.rss-widget-title) { float: right; } diff --git a/src/wp-content/themes/twentytwenty/style-rtl.css b/src/wp-content/themes/twentytwenty/style-rtl.css index d412545acc..aa87bedf03 100644 --- a/src/wp-content/themes/twentytwenty/style-rtl.css +++ b/src/wp-content/themes/twentytwenty/style-rtl.css @@ -4286,7 +4286,7 @@ div.comment:first-of-type { /* Widget: RSS ------------------------------- */ -.widget_rss .widget-title a.rsswidget:first-of-type { +.widget_rss .widget-title a.rsswidget:first-of-type:not(.rss-widget-title) { display: none; } diff --git a/src/wp-content/themes/twentytwenty/style.css b/src/wp-content/themes/twentytwenty/style.css index 80417f5b83..b5a99f90f5 100644 --- a/src/wp-content/themes/twentytwenty/style.css +++ b/src/wp-content/themes/twentytwenty/style.css @@ -4320,7 +4320,7 @@ div.comment:first-of-type { /* Widget: RSS ------------------------------- */ -.widget_rss .widget-title a.rsswidget:first-of-type { +.widget_rss .widget-title a.rsswidget:first-of-type:not(.rss-widget-title) { display: none; } diff --git a/src/wp-includes/widgets/class-wp-widget-rss.php b/src/wp-includes/widgets/class-wp-widget-rss.php index 6c72a2cd15..a265680901 100644 --- a/src/wp-includes/widgets/class-wp-widget-rss.php +++ b/src/wp-includes/widgets/class-wp-widget-rss.php @@ -86,10 +86,31 @@ class WP_Widget_RSS extends WP_Widget { /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */ $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); - $url = strip_tags( $url ); - $icon = includes_url( 'images/rss.png' ); if ( $title ) { - $title = 'RSS ' . esc_html( $title ) . ''; + $feed_link = ''; + $feed_url = strip_tags( $url ); + $feed_icon = includes_url( 'images/rss.png' ); + $feed_link = sprintf( + '%3$s ', + esc_url( $feed_url ), + esc_url( $feed_icon ), + esc_attr__( 'RSS' ), + ( wp_lazy_loading_enabled( 'img', 'rss_widget_feed_icon' ) ? ' loading="lazy"' : '' ) + ); + + /** + * Filters the classic RSS widget's feed icon link. + * + * Themes can remove the icon link by using `add_filter( 'rss_widget_feed_link', '__return_false' );`. + * + * @since 5.9.0 + * + * @param string $feed_link HTML for link to RSS feed. + * @param array $instance Array of settings for the current widget. + */ + $feed_link = apply_filters( 'rss_widget_feed_link', $feed_link, $instance ); + + $title = $feed_link . '' . esc_html( $title ) . ''; } echo $args['before_widget']; diff --git a/tests/phpunit/tests/rest-api/rest-widgets-controller.php b/tests/phpunit/tests/rest-api/rest-widgets-controller.php index 03d4ea0931..d50172f2b3 100644 --- a/tests/phpunit/tests/rest-api/rest-widgets-controller.php +++ b/tests/phpunit/tests/rest-api/rest-widgets-controller.php @@ -394,7 +394,7 @@ class WP_Test_REST_Widgets_Controller extends WP_Test_REST_Controller_Testcase { 'id' => 'rss-1', 'id_base' => 'rss', 'sidebar' => 'sidebar-1', - 'rendered' => 'RSS RSS test', + 'rendered' => 'RSS RSS test', ), array( 'id' => 'testwidget', diff --git a/tests/phpunit/tests/widgets/wpWidgetRss.php b/tests/phpunit/tests/widgets/wpWidgetRss.php index 5953f65f4d..495869f475 100644 --- a/tests/phpunit/tests/widgets/wpWidgetRss.php +++ b/tests/phpunit/tests/widgets/wpWidgetRss.php @@ -94,7 +94,7 @@ class Tests_Widgets_wpWidgetRss extends WP_UnitTestCase { return array( 'when url is given' => array( 'url' => 'https://wordpress.org/news/feed/', - '

', + '

', ), ); }