Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (9 years ago)
Author:
pento
Message:

Code is Poetry.
WordPress' code just... wasn't.
This is now dealt with.

Props jrf, pento, netweb, GaryJ, jdgrimes, westonruter, Greg Sherwood from PHPCS, and everyone who's ever contributed to WPCS and PHPCS.
Fixes #41057.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/widgets/class-wp-widget-tag-cloud.php

    r41867 r42343  
    2424        public function __construct() {
    2525                $widget_ops = array(
    26                         'description' => __( 'A cloud of your most used tags.' ),
     26                        'description'                 => __( 'A cloud of your most used tags.' ),
    2727                        'customize_selective_refresh' => true,
    2828                );
    … …  
    4848                                $title = __( 'Tags' );
    4949                        } else {
    50                                 $tax = get_taxonomy( $current_taxonomy );
     50                                $tax   = get_taxonomy( $current_taxonomy );
    5151                                $title = $tax->labels->name;
    5252                        }
    … …  
    6767                 * @param array $instance Array of settings for the current widget.
    6868                 */
    69                 $tag_cloud = wp_tag_cloud( apply_filters( 'widget_tag_cloud_args', array(
    70                         'taxonomy'   => $current_taxonomy,
    71                         'echo'       => false,
    72                         'show_count' => $show_count,
    73                 ), $instance ) );
     69                $tag_cloud = wp_tag_cloud(
     70                        apply_filters(
     71                                'widget_tag_cloud_args', array(
     72                                        'taxonomy'   => $current_taxonomy,
     73                                        'echo'       => false,
     74                                        'show_count' => $show_count,
     75                                ), $instance
     76                        )
     77                );
    7478
    7579                if ( empty( $tag_cloud ) ) {
    … …  
    104108         */
    105109        public function update( $new_instance, $old_instance ) {
    106                 $instance = array();
    107                 $instance['title'] = sanitize_text_field( $new_instance['title'] );
    108                 $instance['count'] = ! empty( $new_instance['count'] ) ? 1 : 0;
    109                 $instance['taxonomy'] = stripslashes($new_instance['taxonomy']);
     110                $instance             = array();
     111                $instance['title']    = sanitize_text_field( $new_instance['title'] );
     112                $instance['count']    = ! empty( $new_instance['count'] ) ? 1 : 0;
     113                $instance['taxonomy'] = stripslashes( $new_instance['taxonomy'] );
    110114                return $instance;
    111115        }
    … …  
    119123         */
    120124        public function form( $instance ) {
    121                 $current_taxonomy = $this->_get_current_taxonomy($instance);
    122                 $title_id = $this->get_field_id( 'title' );
    123                 $count = isset( $instance['count'] ) ? (bool) $instance['count'] : false;
     125                $current_taxonomy  = $this->_get_current_taxonomy( $instance );
     126                $title_id          = $this->get_field_id( 'title' );
     127                $count             = isset( $instance['count'] ) ? (bool) $instance['count'] : false;
    124128                $instance['title'] = ! empty( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
    125129
    126                 echo '<p><label for="' . $title_id .'">' . __( 'Title:' ) . '</label>
    127                         <input type="text" class="widefat" id="' . $title_id .'" name="' . $this->get_field_name( 'title' ) .'" value="' . $instance['title'] .'" />
     130                echo '<p><label for="' . $title_id . '">' . __( 'Title:' ) . '</label>
     131                        <input type="text" class="widefat" id="' . $title_id . '" name="' . $this->get_field_name( 'title' ) . '" value="' . $instance['title'] . '" />
    128132                </p>';
    129133
    130134                $taxonomies = get_taxonomies( array( 'show_tagcloud' => true ), 'object' );
    131                 $id = $this->get_field_id( 'taxonomy' );
    132                 $name = $this->get_field_name( 'taxonomy' );
    133                 $input = '<input type="hidden" id="' . $id . '" name="' . $name . '" value="%s" />';
     135                $id         = $this->get_field_id( 'taxonomy' );
     136                $name       = $this->get_field_name( 'taxonomy' );
     137                $input      = '<input type="hidden" id="' . $id . '" name="' . $name . '" value="%s" />';
    134138
    135139                $count_checkbox = sprintf(
    … …  
    143147                switch ( count( $taxonomies ) ) {
    144148
    145                 // No tag cloud supporting taxonomies found, display error message
    146                 case 0:
    147                         echo '<p>' . __( 'The tag cloud will not be displayed since there are no taxonomies that support the tag cloud widget.' ) . '</p>';
    148                         printf( $input, '' );
    149                         break;
    150 
    151                 // Just a single tag cloud supporting taxonomy found, no need to display a select.
    152                 case 1:
    153                         $keys = array_keys( $taxonomies );
    154                         $taxonomy = reset( $keys );
    155                         printf( $input, esc_attr( $taxonomy ) );
    156                         echo $count_checkbox;
    157                         break;
    158 
    159                 // More than one tag cloud supporting taxonomy found, display a select.
    160                 default:
    161                         printf(
    162                                 '<p><label for="%1$s">%2$s</label>' .
    163                                 '<select class="widefat" id="%1$s" name="%3$s">',
    164                                 $id,
    165                                 __( 'Taxonomy:' ),
    166                                 $name
    167                         );
    168 
    169                         foreach ( $taxonomies as $taxonomy => $tax ) {
     149                        // No tag cloud supporting taxonomies found, display error message
     150                        case 0:
     151                                echo '<p>' . __( 'The tag cloud will not be displayed since there are no taxonomies that support the tag cloud widget.' ) . '</p>';
     152                                printf( $input, '' );
     153                                break;
     154
     155                        // Just a single tag cloud supporting taxonomy found, no need to display a select.
     156                        case 1:
     157                                $keys     = array_keys( $taxonomies );
     158                                $taxonomy = reset( $keys );
     159                                printf( $input, esc_attr( $taxonomy ) );
     160                                echo $count_checkbox;
     161                                break;
     162
     163                        // More than one tag cloud supporting taxonomy found, display a select.
     164                        default:
    170165                                printf(
    171                                         '<option value="%s"%s>%s</option>',
    172                                         esc_attr( $taxonomy ),
    173                                         selected( $taxonomy, $current_taxonomy, false ),
    174                                         $tax->labels->name
     166                                        '<p><label for="%1$s">%2$s</label>' .
     167                                        '<select class="widefat" id="%1$s" name="%3$s">',
     168                                        $id,
     169                                        __( 'Taxonomy:' ),
     170                                        $name
    175171                                );
    176                         }
    177 
    178                         echo '</select></p>' . $count_checkbox;
     172
     173                                foreach ( $taxonomies as $taxonomy => $tax ) {
     174                                        printf(
     175                                                '<option value="%s"%s>%s</option>',
     176                                                esc_attr( $taxonomy ),
     177                                                selected( $taxonomy, $current_taxonomy, false ),
     178                                                $tax->labels->name
     179                                        );
     180                                }
     181
     182                                echo '</select></p>' . $count_checkbox;
    179183                }
    180184        }
    … …  
    188192         * @return string Name of the current taxonomy if set, otherwise 'post_tag'.
    189193         */
    190         public function _get_current_taxonomy($instance) {
    191                 if ( !empty($instance['taxonomy']) && taxonomy_exists($instance['taxonomy']) )
     194        public function _get_current_taxonomy( $instance ) {
     195                if ( ! empty( $instance['taxonomy'] ) && taxonomy_exists( $instance['taxonomy'] ) ) {
    192196                        return $instance['taxonomy'];
     197                }
    193198
    194199                return 'post_tag';
Note: See TracChangeset for help on using the changeset viewer.