Make WordPress Core

Ticket #32065: 32065.diff

File 32065.diff, 6.9 KB (added by donmhico, 6 years ago)
  • src/wp-includes/widgets.php

    diff --git src/wp-includes/widgets.php src/wp-includes/widgets.php
    index c3be679516..20350ee627 100644
    function wp_widget_rss_output( $rss, $args = array() ) { 
    15421542 *
    15431543 * The options for what fields are displayed for the RSS form are all booleans
    15441544 * and are as follows: 'url', 'title', 'items', 'show_summary', 'show_author',
    1545  * 'show_date'.
     1545 * 'show_date', 'hide_empty_rss'.
    15461546 *
    15471547 * @since 2.5.0
     1548 * @since 5.3.0 Added `hide_empty_rss` field.
    15481549 *
    15491550 * @param array|string $args Values for input fields.
    15501551 * @param array $inputs Override default display options.
    15511552 */
    15521553function wp_widget_rss_form( $args, $inputs = null ) {
    15531554        $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,
    15601562        );
    15611563        $inputs         = wp_parse_args( $inputs, $default_inputs );
    15621564
    function wp_widget_rss_form( $args, $inputs = null ) { 
    15681570                $args['items'] = 10;
    15691571        }
    15701572
    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'];
    15741577
    15751578        if ( ! empty( $args['error'] ) ) {
    15761579                echo '<p class="widget-error"><strong>' . __( 'RSS Error:' ) . '</strong> ' . $args['error'] . '</p>';
    function wp_widget_rss_form( $args, $inputs = null ) { 
    16041607        <label for="rss-show-date-<?php echo $esc_number; ?>"><?php _e( 'Display item date?' ); ?></label></p>
    16051608        <?php
    16061609        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 ) :
    16081616        if ( 'hidden' === $inputs[ $input ] ) :
    16091617                $id = str_replace( '_', '-', $input );
    16101618                ?>
    foreach ( array_keys( $default_inputs ) as $input ) : 
    16211629 * default, which is 10.
    16221630 *
    16231631 * 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.
    16251634 * All respectively in the order of the array elements.
    16261635 *
    16271636 * @since 2.5.0
     1637 * @since 5.3.0 Added `hide_empty_rss` field.
    16281638 *
    16291639 * @param array $widget_rss RSS widget feed data. Expects unescaped data.
    16301640 * @param bool $check_feed Optional, default is true. Whether to check feed for errors.
    function wp_widget_rss_process( $widget_rss, $check_feed = true ) { 
    16351645        if ( $items < 1 || 20 < $items ) {
    16361646                $items = 10;
    16371647        }
    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;
    16431654
    16441655        if ( $check_feed ) {
    16451656                $rss   = fetch_feed( $url );
    function wp_widget_rss_process( $widget_rss, $check_feed = true ) { 
    16581669                }
    16591670        }
    16601671
    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' );
    16621673}
    16631674
    16641675/**
  • src/wp-includes/widgets/class-wp-widget-rss.php

    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 { 
    6666                $desc  = '';
    6767                $link  = '';
    6868
     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
    6989                if ( ! is_wp_error( $rss ) ) {
    7090                        $desc = esc_attr( strip_tags( html_entity_decode( $rss->get_description(), ENT_QUOTES, get_option( 'blog_charset' ) ) ) );
    7191                        if ( empty( $title ) ) {
    class WP_Widget_RSS extends WP_Widget { 
    128148        public function form( $instance ) {
    129149                if ( empty( $instance ) ) {
    130150                        $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,
    138159                        );
    139160                }
    140161                $instance['number'] = $this->number;