Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (8 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/class-wp-term-query.php

    r42209 r42343  
    255255
    256256        if ( 'all' == $query['get'] ) {
    257             $query['childless'] = false;
    258             $query['child_of'] = 0;
    259             $query['hide_empty'] = 0;
     257            $query['childless']    = false;
     258            $query['child_of']     = 0;
     259            $query['hide_empty']   = 0;
    260260            $query['hierarchical'] = false;
    261             $query['pad_counts'] = false;
     261            $query['pad_counts']   = false;
    262262        }
    263263
     
    331331        if ( ! $has_hierarchical_tax ) {
    332332            $args['hierarchical'] = false;
    333             $args['pad_counts'] = false;
     333            $args['pad_counts']   = false;
    334334        }
    335335
     
    340340
    341341        if ( 'all' == $args['get'] ) {
    342             $args['childless'] = false;
    343             $args['child_of'] = 0;
    344             $args['hide_empty'] = 0;
     342            $args['childless']    = false;
     343            $args['child_of']     = 0;
     344            $args['hide_empty']   = 0;
    345345            $args['hierarchical'] = false;
    346             $args['pad_counts'] = false;
     346            $args['pad_counts']   = false;
    347347        }
    348348
     
    412412        $inclusions = '';
    413413        if ( ! empty( $include ) ) {
    414             $exclude = '';
     414            $exclude      = '';
    415415            $exclude_tree = '';
    416             $inclusions = implode( ',', wp_parse_id_list( $include ) );
     416            $inclusions   = implode( ',', wp_parse_id_list( $include ) );
    417417        }
    418418
     
    423423        $exclusions = array();
    424424        if ( ! empty( $exclude_tree ) ) {
    425             $exclude_tree = wp_parse_id_list( $exclude_tree );
     425            $exclude_tree      = wp_parse_id_list( $exclude_tree );
    426426            $excluded_children = $exclude_tree;
    427427            foreach ( $exclude_tree as $extrunk ) {
    428428                $excluded_children = array_merge(
    429429                    $excluded_children,
    430                     (array) get_terms( reset( $taxonomies ), array(
    431                         'child_of' => intval( $extrunk ),
    432                         'fields' => 'ids',
    433                         'hide_empty' => 0
    434                     ) )
     430                    (array) get_terms(
     431                        reset( $taxonomies ), array(
     432                            'child_of'   => intval( $extrunk ),
     433                            'fields'     => 'ids',
     434                            'hide_empty' => 0,
     435                        )
     436                    )
    435437                );
    436438            }
     
    447449            foreach ( $taxonomies as $_tax ) {
    448450                $term_hierarchy = _get_term_hierarchy( $_tax );
    449                 $exclusions = array_merge( array_keys( $term_hierarchy ), $exclusions );
     451                $exclusions     = array_merge( array_keys( $term_hierarchy ), $exclusions );
    450452            }
    451453        }
     
    491493        ) {
    492494            if ( is_array( $args['slug'] ) ) {
    493                 $slug = array_map( 'sanitize_title', $args['slug'] );
     495                $slug                               = array_map( 'sanitize_title', $args['slug'] );
    494496                $this->sql_clauses['where']['slug'] = "t.slug IN ('" . implode( "', '", $slug ) . "')";
    495497            } else {
    496                 $slug = sanitize_title( $args['slug'] );
     498                $slug                               = sanitize_title( $args['slug'] );
    497499                $this->sql_clauses['where']['slug'] = "t.slug = '$slug'";
    498500            }
     
    504506                $this->sql_clauses['where']['term_taxonomy_id'] = "tt.term_taxonomy_id IN ({$tt_ids})";
    505507            } else {
    506                 $this->sql_clauses['where']['term_taxonomy_id'] = $wpdb->prepare( "tt.term_taxonomy_id = %d", $args['term_taxonomy_id'] );
     508                $this->sql_clauses['where']['term_taxonomy_id'] = $wpdb->prepare( 'tt.term_taxonomy_id = %d', $args['term_taxonomy_id'] );
    507509            }
    508510        }
    509511
    510512        if ( ! empty( $args['name__like'] ) ) {
    511             $this->sql_clauses['where']['name__like'] = $wpdb->prepare( "t.name LIKE %s", '%' . $wpdb->esc_like( $args['name__like'] ) . '%' );
     513            $this->sql_clauses['where']['name__like'] = $wpdb->prepare( 't.name LIKE %s', '%' . $wpdb->esc_like( $args['name__like'] ) . '%' );
    512514        }
    513515
    514516        if ( ! empty( $args['description__like'] ) ) {
    515             $this->sql_clauses['where']['description__like'] = $wpdb->prepare( "tt.description LIKE %s", '%' . $wpdb->esc_like( $args['description__like'] ) . '%' );
     517            $this->sql_clauses['where']['description__like'] = $wpdb->prepare( 'tt.description LIKE %s', '%' . $wpdb->esc_like( $args['description__like'] ) . '%' );
    516518        }
    517519
     
    522524            }
    523525
    524             $object_ids = implode( ', ', array_map( 'intval', $object_ids ) );
     526            $object_ids                               = implode( ', ', array_map( 'intval', $object_ids ) );
    525527            $this->sql_clauses['where']['object_ids'] = "tr.object_id IN ($object_ids)";
    526528        }
     
    535537
    536538        if ( '' !== $parent ) {
    537             $parent = (int) $parent;
     539            $parent                               = (int) $parent;
    538540            $this->sql_clauses['where']['parent'] = "tt.parent = '$parent'";
    539541        }
     
    543545            $hierarchical = false;
    544546        }
    545         if ( $args['hide_empty'] && !$hierarchical ) {
     547        if ( $args['hide_empty'] && ! $hierarchical ) {
    546548            $this->sql_clauses['where']['count'] = 'tt.count > 0';
    547549        }
     
    561563        }
    562564
    563 
    564565        if ( ! empty( $args['search'] ) ) {
    565566            $this->sql_clauses['where']['search'] = $this->get_search_sql( $args['search'] );
     
    567568
    568569        // Meta query support.
    569         $join = '';
     570        $join     = '';
    570571        $distinct = '';
    571572
    572573        // Reparse meta_query query_vars, in case they were modified in a 'pre_get_terms' callback.
    573574        $this->meta_query->parse_query_vars( $this->query_vars );
    574         $mq_sql = $this->meta_query->get_sql( 'term', 't', 'term_id' );
     575        $mq_sql       = $this->meta_query->get_sql( 'term', 't', 'term_id' );
    575576        $meta_clauses = $this->meta_query->get_clauses();
    576577
    577578        if ( ! empty( $meta_clauses ) ) {
    578             $join .= $mq_sql['join'];
     579            $join                                    .= $mq_sql['join'];
    579580            $this->sql_clauses['where']['meta_query'] = preg_replace( '/^\s*AND\s*/', '', $mq_sql['where'] );
    580             $distinct .= "DISTINCT";
     581            $distinct                                .= 'DISTINCT';
    581582
    582583        }
     
    585586        switch ( $args['fields'] ) {
    586587            case 'all':
    587             case 'all_with_object_id' :
    588             case 'tt_ids' :
    589             case 'slugs' :
     588            case 'all_with_object_id':
     589            case 'tt_ids':
     590            case 'slugs':
    590591                $selects = array( 't.*', 'tt.*' );
    591592                if ( 'all_with_object_id' === $args['fields'] && ! empty( $args['object_ids'] ) ) {
     
    602603            case 'count':
    603604                $orderby = '';
    604                 $order = '';
     605                $order   = '';
    605606                $selects = array( 'COUNT(*)' );
    606607                break;
     
    652653        $clauses = apply_filters( 'terms_clauses', compact( 'fields', 'join', 'where', 'distinct', 'orderby', 'order', 'limits' ), $taxonomies, $args );
    653654
    654         $fields = isset( $clauses[ 'fields' ] ) ? $clauses[ 'fields' ] : '';
    655         $join = isset( $clauses[ 'join' ] ) ? $clauses[ 'join' ] : '';
    656         $where = isset( $clauses[ 'where' ] ) ? $clauses[ 'where' ] : '';
    657         $distinct = isset( $clauses[ 'distinct' ] ) ? $clauses[ 'distinct' ] : '';
    658         $orderby = isset( $clauses[ 'orderby' ] ) ? $clauses[ 'orderby' ] : '';
    659         $order = isset( $clauses[ 'order' ] ) ? $clauses[ 'order' ] : '';
    660         $limits = isset( $clauses[ 'limits' ] ) ? $clauses[ 'limits' ] : '';
     655        $fields   = isset( $clauses['fields'] ) ? $clauses['fields'] : '';
     656        $join     = isset( $clauses['join'] ) ? $clauses['join'] : '';
     657        $where    = isset( $clauses['where'] ) ? $clauses['where'] : '';
     658        $distinct = isset( $clauses['distinct'] ) ? $clauses['distinct'] : '';
     659        $orderby  = isset( $clauses['orderby'] ) ? $clauses['orderby'] : '';
     660        $order    = isset( $clauses['order'] ) ? $clauses['order'] : '';
     661        $limits   = isset( $clauses['limits'] ) ? $clauses['limits'] : '';
    661662
    662663        if ( $where ) {
     
    672673
    673674        // $args can be anything. Only use the args defined in defaults to compute the key.
    674         $key = md5( serialize( wp_array_slice_assoc( $args, array_keys( $this->query_var_defaults ) ) ) . serialize( $taxonomies ) . $this->request );
     675        $key          = md5( serialize( wp_array_slice_assoc( $args, array_keys( $this->query_var_defaults ) ) ) . serialize( $taxonomies ) . $this->request );
    675676        $last_changed = wp_cache_get_last_changed( 'terms' );
    676         $cache_key = "get_terms:$key:$last_changed";
    677         $cache = wp_cache_get( $cache_key, 'terms' );
     677        $cache_key    = "get_terms:$key:$last_changed";
     678        $cache        = wp_cache_get( $cache_key, 'terms' );
    678679        if ( false !== $cache ) {
    679680            if ( 'all' === $_fields ) {
     
    757758
    758759                $_tt_ids[ $term->term_id ] = 1;
    759                 $_terms[] = $term;
     760                $_terms[]                  = $term;
    760761            }
    761762
     
    828829     */
    829830    protected function parse_orderby( $orderby_raw ) {
    830         $_orderby = strtolower( $orderby_raw );
     831        $_orderby           = strtolower( $orderby_raw );
    831832        $maybe_orderby_meta = false;
    832833
     
    841842            $orderby = "FIELD( t.term_id, $include )";
    842843        } elseif ( 'slug__in' == $_orderby && ! empty( $this->query_vars['slug'] ) && is_array( $this->query_vars['slug'] ) ) {
    843             $slugs = implode( "', '", array_map( 'sanitize_title_for_query', $this->query_vars['slug'] ) );
     844            $slugs   = implode( "', '", array_map( 'sanitize_title_for_query', $this->query_vars['slug'] ) );
    844845            $orderby = "FIELD( t.slug, '" . $slugs . "')";
    845846        } elseif ( 'none' == $_orderby ) {
     
    894895        }
    895896
    896         $allowed_keys = array();
    897         $primary_meta_key = null;
     897        $allowed_keys       = array();
     898        $primary_meta_key   = null;
    898899        $primary_meta_query = reset( $meta_clauses );
    899900        if ( ! empty( $primary_meta_query['key'] ) ) {
    900901            $primary_meta_key = $primary_meta_query['key'];
    901             $allowed_keys[] = $primary_meta_key;
     902            $allowed_keys[]   = $primary_meta_key;
    902903        }
    903904        $allowed_keys[] = 'meta_value';
     
    909910        }
    910911
    911         switch( $orderby_raw ) {
     912        switch ( $orderby_raw ) {
    912913            case $primary_meta_key:
    913914            case 'meta_value':
     
    927928                    // $orderby corresponds to a meta_query clause.
    928929                    $meta_clause = $meta_clauses[ $orderby_raw ];
    929                     $orderby = "CAST({$meta_clause['alias']}.meta_value AS {$meta_clause['cast']})";
     930                    $orderby     = "CAST({$meta_clause['alias']}.meta_value AS {$meta_clause['cast']})";
    930931                }
    931932                break;
Note: See TracChangeset for help on using the changeset viewer.