diff --git src/wp-includes/widgets.php src/wp-includes/widgets.php
index c3be679516..20350ee627 100644
|
|
function wp_widget_rss_output( $rss, $args = array() ) { |
1542 | 1542 | * |
1543 | 1543 | * The options for what fields are displayed for the RSS form are all booleans |
1544 | 1544 | * and are as follows: 'url', 'title', 'items', 'show_summary', 'show_author', |
1545 | | * 'show_date'. |
| 1545 | * 'show_date', 'hide_empty_rss'. |
1546 | 1546 | * |
1547 | 1547 | * @since 2.5.0 |
| 1548 | * @since 5.3.0 Added `hide_empty_rss` field. |
1548 | 1549 | * |
1549 | 1550 | * @param array|string $args Values for input fields. |
1550 | 1551 | * @param array $inputs Override default display options. |
1551 | 1552 | */ |
1552 | 1553 | function wp_widget_rss_form( $args, $inputs = null ) { |
1553 | 1554 | $default_inputs = array( |
1554 | | 'url' => true, |
1555 | | 'title' => true, |
1556 | | 'items' => true, |
1557 | | 'show_summary' => true, |
1558 | | 'show_author' => true, |
1559 | | 'show_date' => true, |
| 1555 | 'url' => true, |
| 1556 | 'title' => true, |
| 1557 | 'items' => true, |
| 1558 | 'show_summary' => true, |
| 1559 | 'show_author' => true, |
| 1560 | 'show_date' => true, |
| 1561 | 'hide_empty_rss' => true, |
1560 | 1562 | ); |
1561 | 1563 | $inputs = wp_parse_args( $inputs, $default_inputs ); |
1562 | 1564 | |
… |
… |
function wp_widget_rss_form( $args, $inputs = null ) { |
1568 | 1570 | $args['items'] = 10; |
1569 | 1571 | } |
1570 | 1572 | |
1571 | | $args['show_summary'] = isset( $args['show_summary'] ) ? (int) $args['show_summary'] : (int) $inputs['show_summary']; |
1572 | | $args['show_author'] = isset( $args['show_author'] ) ? (int) $args['show_author'] : (int) $inputs['show_author']; |
1573 | | $args['show_date'] = isset( $args['show_date'] ) ? (int) $args['show_date'] : (int) $inputs['show_date']; |
| 1573 | $args['show_summary'] = isset( $args['show_summary'] ) ? (int) $args['show_summary'] : (int) $inputs['show_summary']; |
| 1574 | $args['show_author'] = isset( $args['show_author'] ) ? (int) $args['show_author'] : (int) $inputs['show_author']; |
| 1575 | $args['show_date'] = isset( $args['show_date'] ) ? (int) $args['show_date'] : (int) $inputs['show_date']; |
| 1576 | $args['hide_empty_rss'] = isset( $args['hide_empty_rss'] ) ? (int) $args['hide_empty_rss'] : (int) $inputs['hide_empty_rss']; |
1574 | 1577 | |
1575 | 1578 | if ( ! empty( $args['error'] ) ) { |
1576 | 1579 | echo '<p class="widget-error"><strong>' . __( 'RSS Error:' ) . '</strong> ' . $args['error'] . '</p>'; |
… |
… |
function wp_widget_rss_form( $args, $inputs = null ) { |
1604 | 1607 | <label for="rss-show-date-<?php echo $esc_number; ?>"><?php _e( 'Display item date?' ); ?></label></p> |
1605 | 1608 | <?php |
1606 | 1609 | endif; |
1607 | | foreach ( array_keys( $default_inputs ) as $input ) : |
| 1610 | if ( $inputs['hide_empty_rss'] ) : ?> |
| 1611 | <p><input id="rss-hide-empty-rss-<?php echo $esc_number; ?>" name="widget-rss[<?php echo $esc_number; ?>][hide_empty_rss]" type="checkbox" value="1" <?php checked( $args['hide_empty_rss'] ); ?>/> |
| 1612 | <label for="rss-hide-empty-rss-<?php echo $esc_number; ?>"><?php _e( 'Hide widget to non-admin users if no RSS items are available?' ); ?></label></p> |
| 1613 | <?php |
| 1614 | endif; |
| 1615 | foreach ( array_keys( $default_inputs ) as $input ) : |
1608 | 1616 | if ( 'hidden' === $inputs[ $input ] ) : |
1609 | 1617 | $id = str_replace( '_', '-', $input ); |
1610 | 1618 | ?> |
… |
… |
foreach ( array_keys( $default_inputs ) as $input ) : |
1621 | 1629 | * default, which is 10. |
1622 | 1630 | * |
1623 | 1631 | * The resulting array has the feed title, feed url, feed link (from channel), |
1624 | | * feed items, error (if any), and whether to show summary, author, and date. |
| 1632 | * feed items, error (if any), whether to show summary, author, and date, |
| 1633 | * and whether to show the widget if there's no items from the feed. |
1625 | 1634 | * All respectively in the order of the array elements. |
1626 | 1635 | * |
1627 | 1636 | * @since 2.5.0 |
| 1637 | * @since 5.3.0 Added `hide_empty_rss` field. |
1628 | 1638 | * |
1629 | 1639 | * @param array $widget_rss RSS widget feed data. Expects unescaped data. |
1630 | 1640 | * @param bool $check_feed Optional, default is true. Whether to check feed for errors. |
… |
… |
function wp_widget_rss_process( $widget_rss, $check_feed = true ) { |
1635 | 1645 | if ( $items < 1 || 20 < $items ) { |
1636 | 1646 | $items = 10; |
1637 | 1647 | } |
1638 | | $url = esc_url_raw( strip_tags( $widget_rss['url'] ) ); |
1639 | | $title = isset( $widget_rss['title'] ) ? trim( strip_tags( $widget_rss['title'] ) ) : ''; |
1640 | | $show_summary = isset( $widget_rss['show_summary'] ) ? (int) $widget_rss['show_summary'] : 0; |
1641 | | $show_author = isset( $widget_rss['show_author'] ) ? (int) $widget_rss['show_author'] : 0; |
1642 | | $show_date = isset( $widget_rss['show_date'] ) ? (int) $widget_rss['show_date'] : 0; |
| 1648 | $url = esc_url_raw( strip_tags( $widget_rss['url'] ) ); |
| 1649 | $title = isset( $widget_rss['title'] ) ? trim( strip_tags( $widget_rss['title'] ) ) : ''; |
| 1650 | $show_summary = isset( $widget_rss['show_summary'] ) ? (int) $widget_rss['show_summary'] : 0; |
| 1651 | $show_author = isset( $widget_rss['show_author'] ) ? (int) $widget_rss['show_author'] : 0; |
| 1652 | $show_date = isset( $widget_rss['show_date'] ) ? (int) $widget_rss['show_date'] : 0; |
| 1653 | $hide_empty_rss = isset( $widget_rss['hide_empty_rss'] ) ? (int) $widget_rss['hide_empty_rss'] : 0; |
1643 | 1654 | |
1644 | 1655 | if ( $check_feed ) { |
1645 | 1656 | $rss = fetch_feed( $url ); |
… |
… |
function wp_widget_rss_process( $widget_rss, $check_feed = true ) { |
1658 | 1669 | } |
1659 | 1670 | } |
1660 | 1671 | |
1661 | | return compact( 'title', 'url', 'link', 'items', 'error', 'show_summary', 'show_author', 'show_date' ); |
| 1672 | return compact( 'title', 'url', 'link', 'items', 'error', 'show_summary', 'show_author', 'show_date', 'hide_empty_rss' ); |
1662 | 1673 | } |
1663 | 1674 | |
1664 | 1675 | /** |
diff --git src/wp-includes/widgets/class-wp-widget-rss.php src/wp-includes/widgets/class-wp-widget-rss.php
index 570e7bba43..efecf82fff 100644
|
|
class WP_Widget_RSS extends WP_Widget { |
66 | 66 | $desc = ''; |
67 | 67 | $link = ''; |
68 | 68 | |
| 69 | /** |
| 70 | * Control if the widget is hidden for non-admin users if no RSS items are available. |
| 71 | * |
| 72 | * @since 5.3.0 |
| 73 | * |
| 74 | * @link https://core.trac.wordpress.org/ticket/32065 |
| 75 | */ |
| 76 | if ( $rss instanceof SimplePie ) { |
| 77 | if ( ! $rss->get_item_quantity() ) { |
| 78 | $hide_widget_if_empty_rss = 1; |
| 79 | if ( isset( $instance['hide_empty_rss'] ) ) { |
| 80 | $hide_widget_if_empty_rss = intval( $instance['hide_empty_rss'] ); |
| 81 | } |
| 82 | |
| 83 | if ( $hide_widget_if_empty_rss && !current_user_can( 'edit_theme_options' ) ) { |
| 84 | return; |
| 85 | } |
| 86 | } |
| 87 | } |
| 88 | |
69 | 89 | if ( ! is_wp_error( $rss ) ) { |
70 | 90 | $desc = esc_attr( strip_tags( html_entity_decode( $rss->get_description(), ENT_QUOTES, get_option( 'blog_charset' ) ) ) ); |
71 | 91 | if ( empty( $title ) ) { |
… |
… |
class WP_Widget_RSS extends WP_Widget { |
128 | 148 | public function form( $instance ) { |
129 | 149 | if ( empty( $instance ) ) { |
130 | 150 | $instance = array( |
131 | | 'title' => '', |
132 | | 'url' => '', |
133 | | 'items' => 10, |
134 | | 'error' => false, |
135 | | 'show_summary' => 0, |
136 | | 'show_author' => 0, |
137 | | 'show_date' => 0, |
| 151 | 'title' => '', |
| 152 | 'url' => '', |
| 153 | 'items' => 10, |
| 154 | 'error' => false, |
| 155 | 'show_summary' => 0, |
| 156 | 'show_author' => 0, |
| 157 | 'show_date' => 0, |
| 158 | 'hide_empty_rss' => 1, |
138 | 159 | ); |
139 | 160 | } |
140 | 161 | $instance['number'] = $this->number; |