Ticket #52224: 52224.2.diff
File 52224.2.diff, 11.3 KB (added by , 3 years ago) |
---|
-
src/wp-includes/widgets.php
1535 1535 * Display the RSS entries in a list. 1536 1536 * 1537 1537 * @since 2.5.0 1538 * @since 5.9.0 Added `show_icon` argument. 1538 1539 * 1539 * @param string|array|object $rss RSS url.1540 * @param string|array|object $rss RSS URL. 1540 1541 * @param array $args Widget arguments. 1541 1542 */ 1542 1543 function wp_widget_rss_output( $rss, $args = array() ) { … … 1560 1561 'show_author' => 0, 1561 1562 'show_date' => 0, 1562 1563 'show_summary' => 0, 1564 'show_icon' => 0, 1563 1565 'items' => 0, 1564 1566 ); 1565 1567 $args = wp_parse_args( $args, $default_args ); … … 1571 1573 $show_summary = (int) $args['show_summary']; 1572 1574 $show_author = (int) $args['show_author']; 1573 1575 $show_date = (int) $args['show_date']; 1576 $show_icon = (int) $args['show_icon']; 1574 1577 1575 1578 if ( ! $rss->get_item_quantity() ) { 1576 1579 echo '<ul><li>' . __( 'An error has occurred, which probably means the feed is down. Try again later.' ) . '</li></ul>'; … … 1643 1646 * 1644 1647 * The options for what fields are displayed for the RSS form are all booleans 1645 1648 * and are as follows: 'url', 'title', 'items', 'show_summary', 'show_author', 1646 * 'show_date'. 1649 * 'show_date', 'show_icon'. 1650 . 1647 1651 * 1648 1652 * @since 2.5.0 1653 * @since 5.9.0 Added `show_icon` argument. 1649 1654 * 1650 1655 * @param array|string $args Values for input fields. 1651 1656 * @param array $inputs Override default display options. … … 1658 1663 'show_summary' => true, 1659 1664 'show_author' => true, 1660 1665 'show_date' => true, 1666 'show_icon' => true, 1661 1667 ); 1662 1668 $inputs = wp_parse_args( $inputs, $default_inputs ); 1663 1669 … … 1672 1678 $args['show_summary'] = isset( $args['show_summary'] ) ? (int) $args['show_summary'] : (int) $inputs['show_summary']; 1673 1679 $args['show_author'] = isset( $args['show_author'] ) ? (int) $args['show_author'] : (int) $inputs['show_author']; 1674 1680 $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']; 1675 1682 1676 1683 if ( ! empty( $args['error'] ) ) { 1677 1684 echo '<p class="widget-error"><strong>' . __( 'RSS Error:' ) . '</strong> ' . $args['error'] . '</p>'; … … 1705 1712 <?php endif; if ( $inputs['show_date'] ) : ?> 1706 1713 <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'] ); ?>/> 1707 1714 <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 /> 1708 1718 <?php endif; ?> 1709 1719 </p> 1710 1720 <?php … … 1726 1736 * default, which is 10. 1727 1737 * 1728 1738 * 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. 1730 1740 * All respectively in the order of the array elements. 1731 1741 * 1732 1742 * @since 2.5.0 1743 * @since 5.9.0 Added `show_icon` argument. 1733 1744 * 1734 1745 * @param array $widget_rss RSS widget feed data. Expects unescaped data. 1735 1746 * @param bool $check_feed Optional. Whether to check feed for errors. Default true. … … 1745 1756 $show_summary = isset( $widget_rss['show_summary'] ) ? (int) $widget_rss['show_summary'] : 0; 1746 1757 $show_author = isset( $widget_rss['show_author'] ) ? (int) $widget_rss['show_author'] : 0; 1747 1758 $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; 1748 1760 1749 1761 if ( $check_feed ) { 1750 1762 $rss = fetch_feed( $url ); … … 1763 1775 } 1764 1776 } 1765 1777 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' ); 1767 1779 } 1768 1780 1769 1781 /** -
src/wp-includes/widgets/class-wp-widget-rss.php
39 39 * Outputs the content for the current RSS widget instance. 40 40 * 41 41 * @since 2.8.0 42 * @since 5.9.0 Added `show_icon` argument. 42 43 * 43 44 * @param array $args Display arguments including 'before_title', 'after_title', 44 45 * 'before_widget', and 'after_widget'. … … 86 87 /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */ 87 88 $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); 88 89 89 $url = strip_tags( $url );90 $icon = includes_url( 'images/rss.png' );91 90 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>'; 93 117 } 94 118 95 119 echo $args['before_widget']; … … 142 166 * Outputs the settings form for the RSS widget. 143 167 * 144 168 * @since 2.8.0 169 * @since 5.9.0 Added `show_icon` argument. 145 170 * 146 171 * @param array $instance Current settings. 147 172 */ … … 155 180 'show_summary' => 0, 156 181 'show_author' => 0, 157 182 'show_date' => 0, 183 'show_icon' => 0, 158 184 ); 159 185 } 160 186 $instance['number'] = $this->number; -
tests/phpunit/tests/rest-api/rest-widgets-controller.php
319 319 'id' => 'rss-1', 320 320 'id_base' => 'rss', 321 321 '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>', 323 323 'instance' => array( 324 324 'encoded' => base64_encode( 325 325 serialize( -
tests/phpunit/tests/widgets/wpWidgetRss.php
94 94 return array( 95 95 'when url is given' => array( 96 96 '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/">', 98 98 ), 99 99 ); 100 100 }