Make WordPress Core

Ticket #21165: 21165.7.diff

File 21165.7.diff, 3.9 KB (added by DrewAPicture, 8 years ago)

escaping + docblock

  • src/wp-includes/default-widgets.php

     
    653653        public function widget( $args, $instance ) {
    654654                static $first_dropdown = true;
    655655
     656                $current_taxonomy = $this->_get_current_taxonomy( $instance );
     657
    656658                /** This filter is documented in wp-includes/default-widgets.php */
    657659                $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? __( 'Categories' ) : $instance['title'], $instance, $this->id_base );
    658660
     
    665667                        echo $args['before_title'] . $title . $args['after_title'];
    666668                }
    667669
     670                $tax = get_taxonomy( $current_taxonomy );
     671
    668672                $cat_args = array(
    669673                        'orderby'      => 'name',
    670674                        'show_count'   => $c,
    671                         'hierarchical' => $h
     675                        'hierarchical' => $h,
     676                        'taxonomy' => $current_taxonomy
    672677                );
    673678
    674679                if ( $d ) {
     
    677682
    678683                        echo '<label class="screen-reader-text" for="' . esc_attr( $dropdown_id ) . '">' . $title . '</label>';
    679684
    680                         $cat_args['show_option_none'] = __( 'Select Category' );
     685                        $cat_args['show_option_none'] = $tax->labels->select_name;
    681686                        $cat_args['id'] = $dropdown_id;
    682687
    683688                        /**
     
    740745                $instance['count'] = !empty($new_instance['count']) ? 1 : 0;
    741746                $instance['hierarchical'] = !empty($new_instance['hierarchical']) ? 1 : 0;
    742747                $instance['dropdown'] = !empty($new_instance['dropdown']) ? 1 : 0;
     748                $instance['taxonomy'] = stripslashes( $new_instance['taxonomy'] );
    743749
    744750                return $instance;
    745751        }
     
    754760                $count = isset($instance['count']) ? (bool) $instance['count'] :false;
    755761                $hierarchical = isset( $instance['hierarchical'] ) ? (bool) $instance['hierarchical'] : false;
    756762                $dropdown = isset( $instance['dropdown'] ) ? (bool) $instance['dropdown'] : false;
     763                $current_taxonomy = $this->_get_current_taxonomy( $instance );
    757764?>
    758765                <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e( 'Title:' ); ?></label>
    759766                <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" /></p>
    760767
     768                <p>
     769                        <label for="<?php echo esc_attr( $this->get_field_id( 'taxonomy' ) ); ?>"><?php _e( 'Taxonomy:' ) ?></label>
     770                        <select class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'taxonomy' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'taxonomy' ) ); ?>">
     771                        <?php foreach ( get_taxonomies( array(), 'objects' ) as $taxonomy ) : ?>
     772                                <?php
     773                                if ( ! $taxonomy->hierarchical || empty( $taxonomy->labels->name ) ) :
     774                                        continue;
     775                                endif;
     776                                ?>
     777                                <option value="<?php echo esc_attr( $taxonomy->name ); ?>" <?php selected( $taxonomy->name, $current_taxonomy ) ?>><?php echo $taxonomy->labels->name; ?></option>
     778                        <?php endforeach; ?>
     779                        </select>
     780                </p>
     781
    761782                <p><input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('dropdown'); ?>" name="<?php echo $this->get_field_name('dropdown'); ?>"<?php checked( $dropdown ); ?> />
    762783                <label for="<?php echo $this->get_field_id('dropdown'); ?>"><?php _e( 'Display as dropdown' ); ?></label><br />
    763784
     
    766787
    767788                <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('hierarchical'); ?>" name="<?php echo $this->get_field_name('hierarchical'); ?>"<?php checked( $hierarchical ); ?> />
    768789                <label for="<?php echo $this->get_field_id('hierarchical'); ?>"><?php _e( 'Show hierarchy' ); ?></label></p>
    769 <?php
     790        <?php
    770791        }
    771792
     793        /**
     794         * Retrieves the taxonomy for the current widget instance.
     795         *
     796         * @since 4.4.0
     797         * @access public
     798         *
     799         * @param array $instance Current settings.
     800         * @return string Name of the current taxonomy if set, otherwise 'category'.
     801         */
     802        public function _get_current_taxonomy( $instance ) {
     803                if ( ! empty( $instance['taxonomy'] ) && taxonomy_exists( $instance['taxonomy'] ) ) {
     804                        return $instance['taxonomy'];
     805                }
     806                return 'category';
     807        }
     808
    772809}
    773810
    774811/**