Make WordPress Core

Ticket #52224: 52224.2.diff

File 52224.2.diff, 11.3 KB (added by sabernhardt, 3 years ago)

adding an icon display option to widget settings, updating unit tests, fixing lazy load attribute

  • src/wp-includes/widgets.php

     
    15351535 * Display the RSS entries in a list.
    15361536 *
    15371537 * @since 2.5.0
     1538 * @since 5.9.0 Added `show_icon` argument.
    15381539 *
    1539  * @param string|array|object $rss  RSS url.
     1540 * @param string|array|object $rss  RSS URL.
    15401541 * @param array               $args Widget arguments.
    15411542 */
    15421543function wp_widget_rss_output( $rss, $args = array() ) {
     
    15601561                'show_author'  => 0,
    15611562                'show_date'    => 0,
    15621563                'show_summary' => 0,
     1564                'show_icon'    => 0,
    15631565                'items'        => 0,
    15641566        );
    15651567        $args         = wp_parse_args( $args, $default_args );
     
    15711573        $show_summary = (int) $args['show_summary'];
    15721574        $show_author  = (int) $args['show_author'];
    15731575        $show_date    = (int) $args['show_date'];
     1576        $show_icon    = (int) $args['show_icon'];
    15741577
    15751578        if ( ! $rss->get_item_quantity() ) {
    15761579                echo '<ul><li>' . __( 'An error has occurred, which probably means the feed is down. Try again later.' ) . '</li></ul>';
     
    16431646 *
    16441647 * The options for what fields are displayed for the RSS form are all booleans
    16451648 * and are as follows: 'url', 'title', 'items', 'show_summary', 'show_author',
    1646  * 'show_date'.
     1649 * 'show_date', 'show_icon'.
     1650.
    16471651 *
    16481652 * @since 2.5.0
     1653 * @since 5.9.0 Added `show_icon` argument.
    16491654 *
    16501655 * @param array|string $args   Values for input fields.
    16511656 * @param array        $inputs Override default display options.
     
    16581663                'show_summary' => true,
    16591664                'show_author'  => true,
    16601665                'show_date'    => true,
     1666                'show_icon'    => true,
    16611667        );
    16621668        $inputs         = wp_parse_args( $inputs, $default_inputs );
    16631669
     
    16721678        $args['show_summary'] = isset( $args['show_summary'] ) ? (int) $args['show_summary'] : (int) $inputs['show_summary'];
    16731679        $args['show_author']  = isset( $args['show_author'] ) ? (int) $args['show_author'] : (int) $inputs['show_author'];
    16741680        $args['show_date']    = isset( $args['show_date'] ) ? (int) $args['show_date'] : (int) $inputs['show_date'];
     1681        $args['show_icon']    = isset( $args['show_icon'] ) ? (int) $args['show_icon'] : (int) $inputs['show_icon'];
    16751682
    16761683        if ( ! empty( $args['error'] ) ) {
    16771684                echo '<p class="widget-error"><strong>' . __( 'RSS Error:' ) . '</strong> ' . $args['error'] . '</p>';
     
    17051712        <?php endif; if ( $inputs['show_date'] ) : ?>
    17061713                <input id="rss-show-date-<?php echo $esc_number; ?>" name="widget-rss[<?php echo $esc_number; ?>][show_date]" type="checkbox" value="1" <?php checked( $args['show_date'] ); ?>/>
    17071714                <label for="rss-show-date-<?php echo $esc_number; ?>"><?php _e( 'Display item date?' ); ?></label><br />
     1715        <?php endif; if ( $inputs['show_icon'] ) : ?>
     1716                <input id="rss-show-icon-<?php echo $esc_number; ?>" name="widget-rss[<?php echo $esc_number; ?>][show_icon]" type="checkbox" value="1" <?php checked( $args['show_icon'] ); ?>/>
     1717                <label for="rss-show-icon-<?php echo $esc_number; ?>"><?php _e( 'Display feed icon?' ); ?></label><br />
    17081718        <?php endif; ?>
    17091719        </p>
    17101720        <?php
     
    17261736 * default, which is 10.
    17271737 *
    17281738 * The resulting array has the feed title, feed url, feed link (from channel),
    1729  * feed items, error (if any), and whether to show summary, author, and date.
     1739 * feed items, error (if any), and whether to show summary, author, date, and feed icon.
    17301740 * All respectively in the order of the array elements.
    17311741 *
    17321742 * @since 2.5.0
     1743 * @since 5.9.0 Added `show_icon` argument.
    17331744 *
    17341745 * @param array $widget_rss RSS widget feed data. Expects unescaped data.
    17351746 * @param bool  $check_feed Optional. Whether to check feed for errors. Default true.
     
    17451756        $show_summary = isset( $widget_rss['show_summary'] ) ? (int) $widget_rss['show_summary'] : 0;
    17461757        $show_author  = isset( $widget_rss['show_author'] ) ? (int) $widget_rss['show_author'] : 0;
    17471758        $show_date    = isset( $widget_rss['show_date'] ) ? (int) $widget_rss['show_date'] : 0;
     1759        $show_icon    = isset( $widget_rss['show_icon'] ) ? (int) $widget_rss['show_icon'] : 0;
    17481760
    17491761        if ( $check_feed ) {
    17501762                $rss   = fetch_feed( $url );
     
    17631775                }
    17641776        }
    17651777
    1766         return compact( 'title', 'url', 'link', 'items', 'error', 'show_summary', 'show_author', 'show_date' );
     1778        return compact( 'title', 'url', 'link', 'items', 'error', 'show_summary', 'show_author', 'show_date', 'show_icon' );
    17671779}
    17681780
    17691781/**
  • src/wp-includes/widgets/class-wp-widget-rss.php

     
    3939         * Outputs the content for the current RSS widget instance.
    4040         *
    4141         * @since 2.8.0
     42         * @since 5.9.0 Added `show_icon` argument.
    4243         *
    4344         * @param array $args     Display arguments including 'before_title', 'after_title',
    4445         *                        'before_widget', and 'after_widget'.
     
    8687                /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */
    8788                $title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
    8889
    89                 $url  = strip_tags( $url );
    90                 $icon = includes_url( 'images/rss.png' );
    9190                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>';
     91                        $feed_link = '';
     92                        if ( ! isset( $instance['show_icon'] ) || $instance['show_icon'] ) {
     93                                $feed_url  = strip_tags( $url );
     94                                $feed_icon = includes_url( 'images/rss.png' );
     95                                $feed_link = sprintf(
     96                                        '<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> ',
     97                                        esc_url( $feed_url ),
     98                                        esc_url( $feed_icon ),
     99                                        esc_attr__( 'RSS' ),
     100                                        ( wp_lazy_loading_enabled( 'img', 'rss_widget_feed_icon' ) ? ' loading="lazy"' : '' )
     101                                );
     102                        }
     103
     104                        /**
     105                         * Filters the classic RSS widget's feed icon link.
     106                         *
     107                         * Themes can remove the icon link by using `add_filter( 'rss_widget_feed_link', '__return_false' );`.
     108                         *
     109                         * @since 5.9.0
     110                         *
     111                         * @param string $feed_link HTML for link to RSS feed.
     112                         * @param array  $instance  Array of settings for the current widget.
     113                         */
     114                        $feed_link = apply_filters( 'rss_widget_feed_link', $feed_link, $instance );
     115
     116                        $title = $feed_link . '<a class="rsswidget rss-widget-title" href="' . esc_url( $link ) . '">' . esc_html( $title ) . '</a>';
    93117                }
    94118
    95119                echo $args['before_widget'];
     
    142166         * Outputs the settings form for the RSS widget.
    143167         *
    144168         * @since 2.8.0
     169         * @since 5.9.0 Added `show_icon` argument.
    145170         *
    146171         * @param array $instance Current settings.
    147172         */
     
    155180                                'show_summary' => 0,
    156181                                'show_author'  => 0,
    157182                                'show_date'    => 0,
     183                                'show_icon'    => 0,
    158184                        );
    159185                }
    160186                $instance['number'] = $this->number;
  • tests/phpunit/tests/rest-api/rest-widgets-controller.php

     
    319319                                        'id'       => 'rss-1',
    320320                                        'id_base'  => 'rss',
    321321                                        'sidebar'  => 'sidebar-1',
    322                                         '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>',
     322                                        '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>',
    323323                                        'instance' => array(
    324324                                                'encoded' => base64_encode(
    325325                                                        serialize(
  • tests/phpunit/tests/widgets/wpWidgetRss.php

     
    9494                return array(
    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                );
    100100        }