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-admin/includes/class-wp-terms-list-table.php

    r41684 r42343  
    3939                global $post_type, $taxonomy, $action, $tax;
    4040
    41                 parent::__construct( array(
    42                         'plural' => 'tags',
    43                         'singular' => 'tag',
    44                         'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
    45                 ) );
     41                parent::__construct(
     42                        array(
     43                                'plural'   => 'tags',
     44                                'singular' => 'tag',
     45                                'screen'   => isset( $args['screen'] ) ? $args['screen'] : null,
     46                        )
     47                );
    4648
    4749                $action    = $this->screen->action;
    … …  
    4951                $taxonomy  = $this->screen->taxonomy;
    5052
    51                 if ( empty( $taxonomy ) )
     53                if ( empty( $taxonomy ) ) {
    5254                        $taxonomy = 'post_tag';
    53 
    54                 if ( ! taxonomy_exists( $taxonomy ) )
     55                }
     56
     57                if ( ! taxonomy_exists( $taxonomy ) ) {
    5558                        wp_die( __( 'Invalid taxonomy.' ) );
     59                }
    5660
    5761                $tax = get_taxonomy( $taxonomy );
    5862
    5963                // @todo Still needed? Maybe just the show_ui part.
    60                 if ( empty( $post_type ) || !in_array( $post_type, get_post_types( array( 'show_ui' => true ) ) ) )
     64                if ( empty( $post_type ) || ! in_array( $post_type, get_post_types( array( 'show_ui' => true ) ) ) ) {
    6165                        $post_type = 'post';
    62 
    63         }
    64 
    65         /**
    66          *
     66                }
     67
     68        }
     69
     70        /**
    6771         * @return bool
    6872         */
    … …  
    106110                }
    107111
    108                 $search = !empty( $_REQUEST['s'] ) ? trim( wp_unslash( $_REQUEST['s'] ) ) : '';
     112                $search = ! empty( $_REQUEST['s'] ) ? trim( wp_unslash( $_REQUEST['s'] ) ) : '';
    109113
    110114                $args = array(
    111115                        'search' => $search,
    112                         'page' => $this->get_pagenum(),
     116                        'page'   => $this->get_pagenum(),
    113117                        'number' => $tags_per_page,
    114118                );
    115119
    116                 if ( !empty( $_REQUEST['orderby'] ) )
     120                if ( ! empty( $_REQUEST['orderby'] ) ) {
    117121                        $args['orderby'] = trim( wp_unslash( $_REQUEST['orderby'] ) );
    118 
    119                 if ( !empty( $_REQUEST['order'] ) )
     122                }
     123
     124                if ( ! empty( $_REQUEST['order'] ) ) {
    120125                        $args['order'] = trim( wp_unslash( $_REQUEST['order'] ) );
     126                }
    121127
    122128                $this->callback_args = $args;
    123129
    124                 $this->set_pagination_args( array(
    125                         'total_items' => wp_count_terms( $this->screen->taxonomy, compact( 'search' ) ),
    126                         'per_page' => $tags_per_page,
    127                 ) );
    128         }
    129 
    130         /**
    131          *
     130                $this->set_pagination_args(
     131                        array(
     132                                'total_items' => wp_count_terms( $this->screen->taxonomy, compact( 'search' ) ),
     133                                'per_page'    => $tags_per_page,
     134                        )
     135                );
     136        }
     137
     138        /**
    132139         * @return bool
    133140         */
    … …  
    144151
    145152        /**
    146          *
    147153         * @return array
    148154         */
    … …  
    158164
    159165        /**
    160          *
    161166         * @return string
    162167         */
    163168        public function current_action() {
    164                 if ( isset( $_REQUEST['action'] ) && isset( $_REQUEST['delete_tags'] ) && ( 'delete' === $_REQUEST['action'] || 'delete' === $_REQUEST['action2'] ) )
     169                if ( isset( $_REQUEST['action'] ) && isset( $_REQUEST['delete_tags'] ) && ( 'delete' === $_REQUEST['action'] || 'delete' === $_REQUEST['action2'] ) ) {
    165170                        return 'bulk-delete';
     171                }
    166172
    167173                return parent::current_action();
    … …  
    169175
    170176        /**
    171          *
    172177         * @return array
    173178         */
    … …  
    190195
    191196        /**
    192          *
    193197         * @return array
    194198         */
    … …  
    199203                        'slug'        => 'slug',
    200204                        'posts'       => 'count',
    201                         'links'       => 'count'
     205                        'links'       => 'count',
    202206                );
    203207        }
    … …  
    208212                $taxonomy = $this->screen->taxonomy;
    209213
    210                 $args = wp_parse_args( $this->callback_args, array(
    211                         'page' => 1,
    212                         'number' => 20,
    213                         'search' => '',
    214                         'hide_empty' => 0
    215                 ) );
     214                $args = wp_parse_args(
     215                        $this->callback_args, array(
     216                                'page'       => 1,
     217                                'number'     => 20,
     218                                'search'     => '',
     219                                'hide_empty' => 0,
     220                        )
     221                );
    216222
    217223                $page = $args['page'];
    … …  
    269275                foreach ( $terms as $key => $term ) {
    270276
    271                         if ( $count >= $end )
     277                        if ( $count >= $end ) {
    272278                                break;
    273 
    274                         if ( $term->parent != $parent && empty( $_REQUEST['s'] ) )
     279                        }
     280
     281                        if ( $term->parent != $parent && empty( $_REQUEST['s'] ) ) {
    275282                                continue;
     283                        }
    276284
    277285                        // If the page starts in a subtree, print the parents.
    278286                        if ( $count == $start && $term->parent > 0 && empty( $_REQUEST['s'] ) ) {
    279287                                $my_parents = $parent_ids = array();
    280                                 $p = $term->parent;
     288                                $p          = $term->parent;
    281289                                while ( $p ) {
    282                                         $my_parent = get_term( $p, $taxonomy );
     290                                        $my_parent    = get_term( $p, $taxonomy );
    283291                                        $my_parents[] = $my_parent;
    284                                         $p = $my_parent->parent;
    285                                         if ( in_array( $p, $parent_ids ) ) // Prevent parent loops.
     292                                        $p            = $my_parent->parent;
     293                                        if ( in_array( $p, $parent_ids ) ) { // Prevent parent loops.
    286294                                                break;
     295                                        }
    287296                                        $parent_ids[] = $p;
    288297                                }
    … …  
    304313                        ++$count;
    305314
    306                         unset( $terms[$key] );
    307 
    308                         if ( isset( $children[$term->term_id] ) && empty( $_REQUEST['s'] ) )
     315                        unset( $terms[ $key ] );
     316
     317                        if ( isset( $children[ $term->term_id ] ) && empty( $_REQUEST['s'] ) ) {
    309318                                $this->_rows( $taxonomy, $terms, $children, $start, $per_page, $count, $term->term_id, $level + 1 );
     319                        }
    310320                }
    311321        }
    … …  
    318328        public function single_row( $tag, $level = 0 ) {
    319329                global $taxonomy;
    320                 $tag = sanitize_term( $tag, $taxonomy );
     330                $tag = sanitize_term( $tag, $taxonomy );
    321331
    322332                $this->level = $level;
    … …  
    419429
    420430                $taxonomy = $this->screen->taxonomy;
    421                 $tax = get_taxonomy( $taxonomy );
    422                 $uri = wp_doing_ajax() ? wp_get_referer() : $_SERVER['REQUEST_URI'];
     431                $tax      = get_taxonomy( $taxonomy );
     432                $uri      = wp_doing_ajax() ? wp_get_referer() : $_SERVER['REQUEST_URI'];
    423433
    424434                $edit_link = add_query_arg(
    … …  
    522532
    523533                $ptype_object = get_post_type_object( $this->screen->post_type );
    524                 if ( ! $ptype_object->show_ui )
     534                if ( ! $ptype_object->show_ui ) {
    525535                        return $count;
     536                }
    526537
    527538                if ( $tax->query_var ) {
    528539                        $args = array( $tax->query_var => $tag->slug );
    529540                } else {
    530                         $args = array( 'taxonomy' => $tax->name, 'term' => $tag->slug );
    531                 }
    532 
    533                 if ( 'post' != $this->screen->post_type )
     541                        $args = array(
     542                                'taxonomy' => $tax->name,
     543                                'term'     => $tag->slug,
     544                        );
     545                }
     546
     547                if ( 'post' != $this->screen->post_type ) {
    534548                        $args['post_type'] = $this->screen->post_type;
    535 
    536                 if ( 'attachment' === $this->screen->post_type )
    537                         return "<a href='" . esc_url ( add_query_arg( $args, 'upload.php' ) ) . "'>$count</a>";
    538 
    539                 return "<a href='" . esc_url ( add_query_arg( $args, 'edit.php' ) ) . "'>$count</a>";
     549                }
     550
     551                if ( 'attachment' === $this->screen->post_type ) {
     552                        return "<a href='" . esc_url( add_query_arg( $args, 'upload.php' ) ) . "'>$count</a>";
     553                }
     554
     555                return "<a href='" . esc_url( add_query_arg( $args, 'edit.php' ) ) . "'>$count</a>";
    540556        }
    541557
    … …  
    546562        public function column_links( $tag ) {
    547563                $count = number_format_i18n( $tag->count );
    548                 if ( $count )
     564                if ( $count ) {
    549565                        $count = "<a href='link-manager.php?cat_id=$tag->term_id'>$count</a>";
     566                }
    550567                return $count;
    551568        }
    … …  
    580597                $tax = get_taxonomy( $this->screen->taxonomy );
    581598
    582                 if ( ! current_user_can( $tax->cap->edit_terms ) )
     599                if ( ! current_user_can( $tax->cap->edit_terms ) ) {
    583600                        return;
     601                }
    584602?>
    585603
    … …  
    594612                                        <span class="input-text-wrap"><input type="text" name="name" class="ptitle" value="" /></span>
    595613                                </label>
    596         <?php if ( !global_terms_enabled() ) { ?>
     614        <?php if ( ! global_terms_enabled() ) { ?>
    597615                                <label>
    598616                                        <span class="title"><?php _e( 'Slug' ); ?></span>
    … …  
    603621        <?php
    604622
    605                 $core_columns = array( 'cb' => true, 'description' => true, 'name' => true, 'slug' => true, 'posts' => true );
     623                $core_columns = array(
     624                        'cb'          => true,
     625                        'description' => true,
     626                        'name'        => true,
     627                        'slug'        => true,
     628                        'posts'       => true,
     629                );
    606630
    607631                list( $columns ) = $this->get_column_info();
    608632
    609                 foreach ( $columns as $column_name => $column_display_name ) {
    610                         if ( isset( $core_columns[$column_name] ) )
    611                                 continue;
    612 
    613                         /** This action is documented in wp-admin/includes/class-wp-posts-list-table.php */
    614                         do_action( 'quick_edit_custom_box', $column_name, 'edit-tags', $this->screen->taxonomy );
    615                 }
     633        foreach ( $columns as $column_name => $column_display_name ) {
     634                if ( isset( $core_columns[ $column_name ] ) ) {
     635                        continue;
     636                }
     637
     638                /** This action is documented in wp-admin/includes/class-wp-posts-list-table.php */
     639                do_action( 'quick_edit_custom_box', $column_name, 'edit-tags', $this->screen->taxonomy );
     640        }
    616641
    617642        ?>
Note: See TracChangeset for help on using the changeset viewer.