Make WordPress Core

Ticket #39825: docs.patch

File docs.patch, 60.1 KB (added by 1naveengiri, 8 years ago)

These are valid relevant doc for these two arguments.

  • class-wp-term-query.php

     
    176176         *                                                Can be used in conjunction with `$meta_value`.
    177177         *     @type string       $meta_value             Limit terms to those matching a specific metadata value.
    178178         *                                                Usually used in conjunction with `$meta_key`.
     179         *     @type string       $meta_type             Type of object metadata is for (e.g., comment, post, or user).
     180         *     @type string       $meta_compare        Comparison operator to test the 'meta_value'.
    179181         * }
    180182         */
    181183        public function __construct( $query = '' ) {
     
    429431                                        (array) get_terms( $taxonomies[0], array(
    430432                                                'child_of' => intval( $extrunk ),
    431433                                                'fields' => 'ids',
    432                                                 'hide_empty' => 0
     434                                                'hide_empty' => 0,
    433435                                        ) )
    434436                                );
    435437                        }
     
    496498                                $tt_ids = implode( ',', array_map( 'intval', $args['term_taxonomy_id'] ) );
    497499                                $this->sql_clauses['where']['term_taxonomy_id'] = "tt.term_taxonomy_id IN ({$tt_ids})";
    498500                        } else {
    499                                 $this->sql_clauses['where']['term_taxonomy_id'] = $wpdb->prepare( "tt.term_taxonomy_id = %d", $args['term_taxonomy_id'] );
     501                                $this->sql_clauses['where']['term_taxonomy_id'] = $wpdb->prepare( 'tt.term_taxonomy_id = %d', $args['term_taxonomy_id'] );
    500502                        }
    501503                }
    502504
    503505                if ( ! empty( $args['name__like'] ) ) {
    504                         $this->sql_clauses['where']['name__like'] = $wpdb->prepare( "t.name LIKE %s", '%' . $wpdb->esc_like( $args['name__like'] ) . '%' );
     506                        $this->sql_clauses['where']['name__like'] = $wpdb->prepare( 't.name LIKE %s', '%' . $wpdb->esc_like( $args['name__like'] ) . '%' );
    505507                }
    506508
    507509                if ( ! empty( $args['description__like'] ) ) {
    508                         $this->sql_clauses['where']['description__like'] = $wpdb->prepare( "tt.description LIKE %s", '%' . $wpdb->esc_like( $args['description__like'] ) . '%' );
     510                        $this->sql_clauses['where']['description__like'] = $wpdb->prepare( 'tt.description LIKE %s', '%' . $wpdb->esc_like( $args['description__like'] ) . '%' );
    509511                }
    510512
    511513                if ( ! empty( $args['object_ids'] ) ) {
     
    535537                if ( 'count' == $args['fields'] ) {
    536538                        $hierarchical = false;
    537539                }
    538                 if ( $args['hide_empty'] && !$hierarchical ) {
     540                if ( $args['hide_empty'] && ! $hierarchical ) {
    539541                        $this->sql_clauses['where']['count'] = 'tt.count > 0';
    540542                }
    541543
     
    553555                        $limits = '';
    554556                }
    555557
    556 
    557558                if ( ! empty( $args['search'] ) ) {
    558559                        $this->sql_clauses['where']['search'] = $this->get_search_sql( $args['search'] );
    559560                }
     
    570571                if ( ! empty( $meta_clauses ) ) {
    571572                        $join .= $mq_sql['join'];
    572573                        $this->sql_clauses['where']['meta_query'] = preg_replace( '/^\s*AND\s*/', '', $mq_sql['where'] );
    573                         $distinct .= "DISTINCT";
     574                        $distinct .= 'DISTINCT';
    574575
    575576                }
    576577
     
    644645                 */
    645646                $clauses = apply_filters( 'terms_clauses', compact( 'fields', 'join', 'where', 'distinct', 'orderby', 'order', 'limits' ), $taxonomies, $args );
    646647
    647                 $fields = isset( $clauses[ 'fields' ] ) ? $clauses[ 'fields' ] : '';
    648                 $join = isset( $clauses[ 'join' ] ) ? $clauses[ 'join' ] : '';
    649                 $where = isset( $clauses[ 'where' ] ) ? $clauses[ 'where' ] : '';
    650                 $distinct = isset( $clauses[ 'distinct' ] ) ? $clauses[ 'distinct' ] : '';
    651                 $orderby = isset( $clauses[ 'orderby' ] ) ? $clauses[ 'orderby' ] : '';
    652                 $order = isset( $clauses[ 'order' ] ) ? $clauses[ 'order' ] : '';
    653                 $limits = isset( $clauses[ 'limits' ] ) ? $clauses[ 'limits' ] : '';
     648                $fields = isset( $clauses['fields'] ) ? $clauses['fields'] : '';
     649                $join = isset( $clauses['join'] ) ? $clauses['join'] : '';
     650                $where = isset( $clauses['where'] ) ? $clauses['where'] : '';
     651                $distinct = isset( $clauses['distinct'] ) ? $clauses['distinct'] : '';
     652                $orderby = isset( $clauses['orderby'] ) ? $clauses['orderby'] : '';
     653                $order = isset( $clauses['order'] ) ? $clauses['order'] : '';
     654                $limits = isset( $clauses['limits'] ) ? $clauses['limits'] : '';
    654655
    655656                if ( $where ) {
    656657                        $where = "WHERE $where";
     
    900901                        return $orderby;
    901902                }
    902903
    903                 switch( $orderby_raw ) {
     904                switch ( $orderby_raw ) {
    904905                        case $primary_meta_key:
    905906                        case 'meta_value':
    906907                                if ( ! empty( $primary_meta_query['type'] ) ) {
  • taxonomy.php

     
    3939                $rewrite = array(
    4040                        'category' => array(
    4141                                'hierarchical' => true,
    42                                 'slug' => get_option('category_base') ? get_option('category_base') : 'category',
    43                                 'with_front' => ! get_option('category_base') || $wp_rewrite->using_index_permalinks(),
     42                                'slug' => get_option( 'category_base' ) ? get_option( 'category_base' ) : 'category',
     43                                'with_front' => ! get_option( 'category_base' ) || $wp_rewrite->using_index_permalinks(),
    4444                                'ep_mask' => EP_CATEGORIES,
    4545                        ),
    4646                        'post_tag' => array(
    4747                                'hierarchical' => false,
    48                                 'slug' => get_option('tag_base') ? get_option('tag_base') : 'tag',
    49                                 'with_front' => ! get_option('tag_base') || $wp_rewrite->using_index_permalinks(),
     48                                'slug' => get_option( 'tag_base' ) ? get_option( 'tag_base' ) : 'tag',
     49                                'with_front' => ! get_option( 'tag_base' ) || $wp_rewrite->using_index_permalinks(),
    5050                                'ep_mask' => EP_TAGS,
    5151                        ),
    5252                        'post_format' => $post_format_base ? array( 'slug' => $post_format_base ) : false,
     
    170170
    171171        $field = ('names' == $output) ? 'name' : false;
    172172
    173         return wp_filter_object_list($wp_taxonomies, $args, $operator, $field);
     173        return wp_filter_object_list( $wp_taxonomies, $args, $operator, $field );
    174174}
    175175
    176176/**
     
    197197function get_object_taxonomies( $object, $output = 'names' ) {
    198198        global $wp_taxonomies;
    199199
    200         if ( is_object($object) ) {
    201                 if ( $object->post_type == 'attachment' )
     200        if ( is_object( $object ) ) {
     201                if ( $object->post_type == 'attachment' ) {
    202202                        return get_attachment_taxonomies( $object, $output );
     203                }
    203204                $object = $object->post_type;
    204205        }
    205206
     
    207208
    208209        $taxonomies = array();
    209210        foreach ( (array) $wp_taxonomies as $tax_name => $tax_obj ) {
    210                 if ( array_intersect($object, (array) $tax_obj->object_type) ) {
    211                         if ( 'names' == $output )
     211                if ( array_intersect( $object, (array) $tax_obj->object_type ) ) {
     212                        if ( 'names' == $output ) {
    212213                                $taxonomies[] = $tax_name;
    213                         else
    214                                 $taxonomies[ $tax_name ] = $tax_obj;
     214                        } else { $taxonomies[ $tax_name ] = $tax_obj;
     215                        }
    215216                }
    216217        }
    217218
     
    234235function get_taxonomy( $taxonomy ) {
    235236        global $wp_taxonomies;
    236237
    237         if ( ! taxonomy_exists( $taxonomy ) )
     238        if ( ! taxonomy_exists( $taxonomy ) ) {
    238239                return false;
     240        }
    239241
    240         return $wp_taxonomies[$taxonomy];
     242        return $wp_taxonomies[ $taxonomy ];
    241243}
    242244
    243245/**
     
    255257function taxonomy_exists( $taxonomy ) {
    256258        global $wp_taxonomies;
    257259
    258         return isset( $wp_taxonomies[$taxonomy] );
     260        return isset( $wp_taxonomies[ $taxonomy ] );
    259261}
    260262
    261263/**
     
    271273 * @param string $taxonomy Name of taxonomy object.
    272274 * @return bool Whether the taxonomy is hierarchical.
    273275 */
    274 function is_taxonomy_hierarchical($taxonomy) {
    275         if ( ! taxonomy_exists($taxonomy) )
     276function is_taxonomy_hierarchical( $taxonomy ) {
     277        if ( ! taxonomy_exists( $taxonomy ) ) {
    276278                return false;
     279        }
    277280
    278         $taxonomy = get_taxonomy($taxonomy);
     281        $taxonomy = get_taxonomy( $taxonomy );
    279282        return $taxonomy->hierarchical;
    280283}
    281284
     
    371374function register_taxonomy( $taxonomy, $object_type, $args = array() ) {
    372375        global $wp_taxonomies;
    373376
    374         if ( ! is_array( $wp_taxonomies ) )
     377        if ( ! is_array( $wp_taxonomies ) ) {
    375378                $wp_taxonomies = array();
     379        }
    376380
    377381        $args = wp_parse_args( $args );
    378382
     
    388392
    389393        $taxonomy_object->add_hooks();
    390394
    391 
    392395        /**
    393396         * Fires after a taxonomy is registered.
    394397         *
     
    485488function get_taxonomy_labels( $tax ) {
    486489        $tax->labels = (array) $tax->labels;
    487490
    488         if ( isset( $tax->helps ) && empty( $tax->labels['separate_items_with_commas'] ) )
     491        if ( isset( $tax->helps ) && empty( $tax->labels['separate_items_with_commas'] ) ) {
    489492                $tax->labels['separate_items_with_commas'] = $tax->helps;
     493        }
    490494
    491         if ( isset( $tax->no_tagcloud ) && empty( $tax->labels['not_found'] ) )
     495        if ( isset( $tax->no_tagcloud ) && empty( $tax->labels['not_found'] ) ) {
    492496                $tax->labels['not_found'] = $tax->no_tagcloud;
     497        }
    493498
    494499        $nohier_vs_hier_defaults = array(
    495500                'name' => array( _x( 'Tags', 'taxonomy general name' ), _x( 'Categories', 'taxonomy general name' ) ),
     
    550555 * @param string $object_type Name of the object type.
    551556 * @return bool True if successful, false if not.
    552557 */
    553 function register_taxonomy_for_object_type( $taxonomy, $object_type) {
     558function register_taxonomy_for_object_type( $taxonomy, $object_type ) {
    554559        global $wp_taxonomies;
    555560
    556         if ( !isset($wp_taxonomies[$taxonomy]) )
     561        if ( ! isset( $wp_taxonomies[ $taxonomy ] ) ) {
    557562                return false;
     563        }
    558564
    559         if ( ! get_post_type_object($object_type) )
     565        if ( ! get_post_type_object( $object_type ) ) {
    560566                return false;
     567        }
    561568
    562         if ( ! in_array( $object_type, $wp_taxonomies[$taxonomy]->object_type ) )
    563                 $wp_taxonomies[$taxonomy]->object_type[] = $object_type;
     569        if ( ! in_array( $object_type, $wp_taxonomies[ $taxonomy ]->object_type ) ) {
     570                $wp_taxonomies[ $taxonomy ]->object_type[] = $object_type;
     571        }
    564572
    565573        // Filter out empties.
    566574        $wp_taxonomies[ $taxonomy ]->object_type = array_filter( $wp_taxonomies[ $taxonomy ]->object_type );
     
    582590function unregister_taxonomy_for_object_type( $taxonomy, $object_type ) {
    583591        global $wp_taxonomies;
    584592
    585         if ( ! isset( $wp_taxonomies[ $taxonomy ] ) )
     593        if ( ! isset( $wp_taxonomies[ $taxonomy ] ) ) {
    586594                return false;
     595        }
    587596
    588         if ( ! get_post_type_object( $object_type ) )
     597        if ( ! get_post_type_object( $object_type ) ) {
    589598                return false;
     599        }
    590600
    591601        $key = array_search( $object_type, $wp_taxonomies[ $taxonomy ]->object_type, true );
    592         if ( false === $key )
     602        if ( false === $key ) {
    593603                return false;
     604        }
    594605
    595606        unset( $wp_taxonomies[ $taxonomy ]->object_type[ $key ] );
    596607        return true;
     
    645656
    646657        $order = ( 'desc' == strtolower( $args['order'] ) ) ? 'DESC' : 'ASC';
    647658
    648         $term_ids = array_map('intval', $term_ids );
     659        $term_ids = array_map( 'intval', $term_ids );
    649660
    650661        $taxonomies = "'" . implode( "', '", array_map( 'esc_sql', $taxonomies ) ) . "'";
    651662        $term_ids = "'" . implode( "', '", $term_ids ) . "'";
    652663
    653         $object_ids = $wpdb->get_col("SELECT tr.object_id FROM $wpdb->term_relationships AS tr INNER JOIN $wpdb->term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy IN ($taxonomies) AND tt.term_id IN ($term_ids) ORDER BY tr.object_id $order");
     664        $object_ids = $wpdb->get_col( "SELECT tr.object_id FROM $wpdb->term_relationships AS tr INNER JOIN $wpdb->term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy IN ($taxonomies) AND tt.term_id IN ($term_ids) ORDER BY tr.object_id $order" );
    654665
    655         if ( ! $object_ids ){
     666        if ( ! $object_ids ) {
    656667                return array();
    657668        }
    658669        return $object_ids;
     
    860871                        break;
    861872                case 'term_taxonomy_id' :
    862873                        $args['term_taxonomy_id'] = $value;
    863                         unset( $args[ 'taxonomy' ] );
     874                        unset( $args['taxonomy'] );
    864875                        break;
    865876                default :
    866877                        return false;
     
    902913
    903914        $term_id = intval( $term_id );
    904915
    905         $terms = _get_term_hierarchy($taxonomy);
     916        $terms = _get_term_hierarchy( $taxonomy );
    906917
    907         if ( ! isset($terms[$term_id]) )
     918        if ( ! isset( $terms[ $term_id ] ) ) {
    908919                return array();
     920        }
    909921
    910         $children = $terms[$term_id];
     922        $children = $terms[ $term_id ];
    911923
    912         foreach ( (array) $terms[$term_id] as $child ) {
     924        foreach ( (array) $terms[ $term_id ] as $child ) {
    913925                if ( $term_id == $child ) {
    914926                        continue;
    915927                }
    916928
    917                 if ( isset($terms[$child]) )
    918                         $children = array_merge($children, get_term_children($child, $taxonomy));
     929                if ( isset( $terms[ $child ] ) ) {
     930                        $children = array_merge( $children, get_term_children( $child, $taxonomy ) );
     931                }
    919932        }
    920933
    921934        return $children;
     
    939952 */
    940953function get_term_field( $field, $term, $taxonomy = '', $context = 'display' ) {
    941954        $term = get_term( $term, $taxonomy );
    942         if ( is_wp_error($term) )
     955        if ( is_wp_error( $term ) ) {
    943956                return $term;
     957        }
    944958
    945         if ( !is_object($term) )
     959        if ( ! is_object( $term ) ) {
    946960                return '';
     961        }
    947962
    948         if ( !isset($term->$field) )
     963        if ( ! isset( $term->$field ) ) {
    949964                return '';
     965        }
    950966
    951967        return sanitize_term_field( $field, $term->$field, $term->term_id, $term->taxonomy, $context );
    952968}
     
    966982function get_term_to_edit( $id, $taxonomy ) {
    967983        $term = get_term( $id, $taxonomy );
    968984
    969         if ( is_wp_error($term) )
     985        if ( is_wp_error( $term ) ) {
    970986                return $term;
     987        }
    971988
    972         if ( !is_object($term) )
     989        if ( ! is_object( $term ) ) {
    973990                return '';
     991        }
    974992
    975         return sanitize_term($term, $taxonomy, 'edit');
     993        return sanitize_term( $term, $taxonomy, 'edit' );
    976994}
    977995
    978996/**
     
    10801098 *                                                conjunction with `$meta_value`.
    10811099 *     @type string       $meta_value             Limit terms to those matching a specific metadata value. Usually used
    10821100 *                                                in conjunction with `$meta_key`.
     1101 *     @type string       $meta_type             Type of object metadata is for (e.g., comment, post, or user).
     1102 *     @type string       $meta_compare        Comparison operator to test the 'meta_value'.
    10831103 * }
    10841104 * @param array $deprecated Argument array, when using the legacy function parameter format. If present, this
    10851105 *                          parameter will be interpreted as `$args`, and the first function parameter will
     
    11631183        }
    11641184
    11651185        if ( wp_term_is_shared( $term_id ) ) {
    1166                 return new WP_Error( 'ambiguous_term_id', __( 'Term meta cannot be added to terms that are shared between taxonomies.'), $term_id );
     1186                return new WP_Error( 'ambiguous_term_id', __( 'Term meta cannot be added to terms that are shared between taxonomies.' ), $term_id );
    11671187        }
    11681188
    11691189        $added = add_metadata( 'term', $term_id, $meta_key, $meta_value, $unique );
     
    12451265        }
    12461266
    12471267        if ( wp_term_is_shared( $term_id ) ) {
    1248                 return new WP_Error( 'ambiguous_term_id', __( 'Term meta cannot be added to terms that are shared between taxonomies.'), $term_id );
     1268                return new WP_Error( 'ambiguous_term_id', __( 'Term meta cannot be added to terms that are shared between taxonomies.' ), $term_id );
    12491269        }
    12501270
    12511271        $updated = update_metadata( 'term', $term_id, $meta_key, $meta_value, $prev_value );
     
    13011321        $select = "SELECT term_id FROM $wpdb->terms as t WHERE ";
    13021322        $tax_select = "SELECT tt.term_id, tt.term_taxonomy_id FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy as tt ON tt.term_id = t.term_id WHERE ";
    13031323
    1304         if ( is_int($term) ) {
    1305                 if ( 0 == $term )
     1324        if ( is_int( $term ) ) {
     1325                if ( 0 == $term ) {
    13061326                        return 0;
     1327                }
    13071328                $where = 't.term_id = %d';
    1308                 if ( !empty($taxonomy) )
    1309                         return $wpdb->get_row( $wpdb->prepare( $tax_select . $where . " AND tt.taxonomy = %s", $term, $taxonomy ), ARRAY_A );
    1310                 else
    1311                         return $wpdb->get_var( $wpdb->prepare( $select . $where, $term ) );
     1329                if ( ! empty( $taxonomy ) ) {
     1330                        return $wpdb->get_row( $wpdb->prepare( $tax_select . $where . ' AND tt.taxonomy = %s', $term, $taxonomy ), ARRAY_A );
     1331                } else { return $wpdb->get_var( $wpdb->prepare( $select . $where, $term ) );
     1332                }
    13121333        }
    13131334
    13141335        $term = trim( wp_unslash( $term ) );
     
    13161337
    13171338        $where = 't.slug = %s';
    13181339        $else_where = 't.name = %s';
    1319         $where_fields = array($slug);
    1320         $else_where_fields = array($term);
     1340        $where_fields = array( $slug );
     1341        $else_where_fields = array( $term );
    13211342        $orderby = 'ORDER BY t.term_id ASC';
    13221343        $limit = 'LIMIT 1';
    1323         if ( !empty($taxonomy) ) {
     1344        if ( ! empty( $taxonomy ) ) {
    13241345                if ( is_numeric( $parent ) ) {
    13251346                        $parent = (int) $parent;
    13261347                        $where_fields[] = $parent;
     
    13321353                $where_fields[] = $taxonomy;
    13331354                $else_where_fields[] = $taxonomy;
    13341355
    1335                 if ( $result = $wpdb->get_row( $wpdb->prepare("SELECT tt.term_id, tt.term_taxonomy_id FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy as tt ON tt.term_id = t.term_id WHERE $where AND tt.taxonomy = %s $orderby $limit", $where_fields), ARRAY_A) )
     1356                if ( $result = $wpdb->get_row( $wpdb->prepare( "SELECT tt.term_id, tt.term_taxonomy_id FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy as tt ON tt.term_id = t.term_id WHERE $where AND tt.taxonomy = %s $orderby $limit", $where_fields ), ARRAY_A ) ) {
    13361357                        return $result;
     1358                }
    13371359
    1338                 return $wpdb->get_row( $wpdb->prepare("SELECT tt.term_id, tt.term_taxonomy_id FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy as tt ON tt.term_id = t.term_id WHERE $else_where AND tt.taxonomy = %s $orderby $limit", $else_where_fields), ARRAY_A);
     1360                return $wpdb->get_row( $wpdb->prepare( "SELECT tt.term_id, tt.term_taxonomy_id FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy as tt ON tt.term_id = t.term_id WHERE $else_where AND tt.taxonomy = %s $orderby $limit", $else_where_fields ), ARRAY_A );
    13391361        }
    13401362
    1341         if ( $result = $wpdb->get_var( $wpdb->prepare("SELECT term_id FROM $wpdb->terms as t WHERE $where $orderby $limit", $where_fields) ) )
     1363        if ( $result = $wpdb->get_var( $wpdb->prepare( "SELECT term_id FROM $wpdb->terms as t WHERE $where $orderby $limit", $where_fields ) ) ) {
    13421364                return $result;
     1365        }
    13431366
    1344         return $wpdb->get_var( $wpdb->prepare("SELECT term_id FROM $wpdb->terms as t WHERE $else_where $orderby $limit", $else_where_fields) );
     1367        return $wpdb->get_var( $wpdb->prepare( "SELECT term_id FROM $wpdb->terms as t WHERE $else_where $orderby $limit", $else_where_fields ) );
    13451368}
    13461369
    13471370/**
     
    13571380 * @return bool Whether `$term2` is a child of `$term1`.
    13581381 */
    13591382function term_is_ancestor_of( $term1, $term2, $taxonomy ) {
    1360         if ( ! isset( $term1->term_id ) )
     1383        if ( ! isset( $term1->term_id ) ) {
    13611384                $term1 = get_term( $term1, $taxonomy );
    1362         if ( ! isset( $term2->parent ) )
     1385        }
     1386        if ( ! isset( $term2->parent ) ) {
    13631387                $term2 = get_term( $term2, $taxonomy );
     1388        }
    13641389
    1365         if ( empty( $term1->term_id ) || empty( $term2->parent ) )
     1390        if ( empty( $term1->term_id ) || empty( $term2->parent ) ) {
    13661391                return false;
    1367         if ( $term2->parent == $term1->term_id )
     1392        }
     1393        if ( $term2->parent == $term1->term_id ) {
    13681394                return true;
     1395        }
    13691396
    13701397        return term_is_ancestor_of( $term1, get_term( $term2->parent, $taxonomy ), $taxonomy );
    13711398}
     
    13871414 *                               'display', 'attribute', or 'js'. Default 'display'.
    13881415 * @return array|object Term with all fields sanitized.
    13891416 */
    1390 function sanitize_term($term, $taxonomy, $context = 'display') {
     1417function sanitize_term( $term, $taxonomy, $context = 'display' ) {
    13911418        $fields = array( 'term_id', 'name', 'description', 'slug', 'count', 'parent', 'term_group', 'term_taxonomy_id', 'object_id' );
    13921419
    13931420        $do_object = is_object( $term );
    13941421
    1395         $term_id = $do_object ? $term->term_id : (isset($term['term_id']) ? $term['term_id'] : 0);
     1422        $term_id = $do_object ? $term->term_id : (isset( $term['term_id'] ) ? $term['term_id'] : 0);
    13961423
    13971424        foreach ( (array) $fields as $field ) {
    13981425                if ( $do_object ) {
    1399                         if ( isset($term->$field) )
    1400                                 $term->$field = sanitize_term_field($field, $term->$field, $term_id, $taxonomy, $context);
     1426                        if ( isset( $term->$field ) ) {
     1427                                $term->$field = sanitize_term_field( $field, $term->$field, $term_id, $taxonomy, $context );
     1428                        }
    14011429                } else {
    1402                         if ( isset($term[$field]) )
    1403                                 $term[$field] = sanitize_term_field($field, $term[$field], $term_id, $taxonomy, $context);
     1430                        if ( isset( $term[ $field ] ) ) {
     1431                                $term[ $field ] = sanitize_term_field( $field, $term[ $field ], $term_id, $taxonomy, $context );
     1432                        }
    14041433                }
    14051434        }
    14061435
    1407         if ( $do_object )
     1436        if ( $do_object ) {
    14081437                $term->filter = $context;
    1409         else
    1410                 $term['filter'] = $context;
     1438        } else { $term['filter'] = $context;
     1439        }
    14111440
    14121441        return $term;
    14131442}
     
    14351464 *                         'attribute', or 'js'.
    14361465 * @return mixed Sanitized field.
    14371466 */
    1438 function sanitize_term_field($field, $value, $term_id, $taxonomy, $context) {
     1467function sanitize_term_field( $field, $value, $term_id, $taxonomy, $context ) {
    14391468        $int_fields = array( 'parent', 'term_id', 'count', 'term_group', 'term_taxonomy_id', 'object_id' );
    14401469        if ( in_array( $field, $int_fields ) ) {
    14411470                $value = (int) $value;
    1442                 if ( $value < 0 )
     1471                if ( $value < 0 ) {
    14431472                        $value = 0;
     1473                }
    14441474        }
    14451475
    1446         if ( 'raw' == $context )
     1476        if ( 'raw' == $context ) {
    14471477                return $value;
     1478        }
    14481479
    14491480        if ( 'edit' == $context ) {
    14501481
     
    14741505                 */
    14751506                $value = apply_filters( "edit_{$taxonomy}_{$field}", $value, $term_id );
    14761507
    1477                 if ( 'description' == $field )
    1478                         $value = esc_html($value); // textarea_escaped
    1479                 else
    1480                         $value = esc_attr($value);
     1508                if ( 'description' == $field ) {
     1509                        $value = esc_html( $value ); // textarea_escaped
     1510                } else { $value = esc_attr( $value );
     1511                }
    14811512        } elseif ( 'db' == $context ) {
    14821513
    14831514                /**
     
    15171548                         */
    15181549                        $value = apply_filters( 'pre_category_nicename', $value );
    15191550                }
    1520 
    15211551        } elseif ( 'rss' == $context ) {
    15221552
    15231553                /**
     
    15761606        }
    15771607
    15781608        if ( 'attribute' == $context ) {
    1579                 $value = esc_attr($value);
     1609                $value = esc_attr( $value );
    15801610        } elseif ( 'js' == $context ) {
    1581                 $value = esc_js($value);
     1611                $value = esc_js( $value );
    15821612        }
    15831613        return $value;
    15841614}
     
    15961626 * @return array|int|WP_Error Number of terms in that taxonomy or WP_Error if the taxonomy does not exist.
    15971627 */
    15981628function wp_count_terms( $taxonomy, $args = array() ) {
    1599         $defaults = array('hide_empty' => false);
    1600         $args = wp_parse_args($args, $defaults);
     1629        $defaults = array( 'hide_empty' => false );
     1630        $args = wp_parse_args( $args, $defaults );
    16011631
    16021632        // backward compatibility
    1603         if ( isset($args['ignore_empty']) ) {
     1633        if ( isset( $args['ignore_empty'] ) ) {
    16041634                $args['hide_empty'] = $args['ignore_empty'];
    1605                 unset($args['ignore_empty']);
     1635                unset( $args['ignore_empty'] );
    16061636        }
    16071637
    16081638        $args['fields'] = 'count';
    16091639
    1610         return get_terms($taxonomy, $args);
     1640        return get_terms( $taxonomy, $args );
    16111641}
    16121642
    16131643/**
     
    16251655function wp_delete_object_term_relationships( $object_id, $taxonomies ) {
    16261656        $object_id = (int) $object_id;
    16271657
    1628         if ( !is_array($taxonomies) )
    1629                 $taxonomies = array($taxonomies);
     1658        if ( ! is_array( $taxonomies ) ) {
     1659                $taxonomies = array( $taxonomies );
     1660        }
    16301661
    16311662        foreach ( (array) $taxonomies as $taxonomy ) {
    16321663                $term_ids = wp_get_object_terms( $object_id, $taxonomy, array( 'fields' => 'ids' ) );
     
    16671698
    16681699        $term = (int) $term;
    16691700
    1670         if ( ! $ids = term_exists($term, $taxonomy) )
     1701        if ( ! $ids = term_exists( $term, $taxonomy ) ) {
    16711702                return false;
    1672         if ( is_wp_error( $ids ) )
     1703        }
     1704        if ( is_wp_error( $ids ) ) {
    16731705                return $ids;
     1706        }
    16741707
    16751708        $tt_id = $ids['term_taxonomy_id'];
    16761709
     
    16781711
    16791712        if ( 'category' == $taxonomy ) {
    16801713                $defaults['default'] = get_option( 'default_category' );
    1681                 if ( $defaults['default'] == $term )
     1714                if ( $defaults['default'] == $term ) {
    16821715                        return 0; // Don't delete the default category
     1716                }
    16831717        }
    16841718
    1685         $args = wp_parse_args($args, $defaults);
     1719        $args = wp_parse_args( $args, $defaults );
    16861720
    16871721        if ( isset( $args['default'] ) ) {
    16881722                $default = (int) $args['default'];
     
    17061740        do_action( 'pre_delete_term', $term, $taxonomy );
    17071741
    17081742        // Update children to point to new parent
    1709         if ( is_taxonomy_hierarchical($taxonomy) ) {
    1710                 $term_obj = get_term($term, $taxonomy);
    1711                 if ( is_wp_error( $term_obj ) )
     1743        if ( is_taxonomy_hierarchical( $taxonomy ) ) {
     1744                $term_obj = get_term( $term, $taxonomy );
     1745                if ( is_wp_error( $term_obj ) ) {
    17121746                        return $term_obj;
     1747                }
    17131748                $parent = $term_obj->parent;
    17141749
    1715                 $edit_ids = $wpdb->get_results( "SELECT term_id, term_taxonomy_id FROM $wpdb->term_taxonomy WHERE `parent` = " . (int)$term_obj->term_id );
     1750                $edit_ids = $wpdb->get_results( "SELECT term_id, term_taxonomy_id FROM $wpdb->term_taxonomy WHERE `parent` = " . (int) $term_obj->term_id );
    17161751                $edit_tt_ids = wp_list_pluck( $edit_ids, 'term_taxonomy_id' );
    17171752
    17181753                /**
     
    17241759                 */
    17251760                do_action( 'edit_term_taxonomies', $edit_tt_ids );
    17261761
    1727                 $wpdb->update( $wpdb->term_taxonomy, compact( 'parent' ), array( 'parent' => $term_obj->term_id) + compact( 'taxonomy' ) );
     1762                $wpdb->update( $wpdb->term_taxonomy, compact( 'parent' ), array( 'parent' => $term_obj->term_id ) + compact( 'taxonomy' ) );
    17281763
    17291764                // Clean the cache for all child terms.
    17301765                $edit_term_ids = wp_list_pluck( $edit_ids, 'term_id' );
     
    17471782
    17481783        foreach ( $object_ids as $object_id ) {
    17491784                $terms = wp_get_object_terms( $object_id, $taxonomy, array( 'fields' => 'ids', 'orderby' => 'none' ) );
    1750                 if ( 1 == count($terms) && isset($default) ) {
    1751                         $terms = array($default);
     1785                if ( 1 == count( $terms ) && isset( $default ) ) {
     1786                        $terms = array( $default );
    17521787                } else {
    1753                         $terms = array_diff($terms, array($term));
    1754                         if (isset($default) && isset($force_default) && $force_default)
    1755                                 $terms = array_merge($terms, array($default));
     1788                        $terms = array_diff( $terms, array( $term ) );
     1789                        if ( isset( $default ) && isset( $force_default ) && $force_default ) {
     1790                                $terms = array_merge( $terms, array( $default ) );
     1791                        }
    17561792                }
    1757                 $terms = array_map('intval', $terms);
     1793                $terms = array_map( 'intval', $terms );
    17581794                wp_set_object_terms( $object_id, $terms, $taxonomy );
    17591795        }
    17601796
    17611797        // Clean the relationship caches for all object types using this term.
    17621798        $tax_object = get_taxonomy( $taxonomy );
    1763         foreach ( $tax_object->object_type as $object_type )
     1799        foreach ( $tax_object->object_type as $object_type ) {
    17641800                clean_object_term_cache( $object_ids, $object_type );
     1801        }
    17651802
    17661803        $term_meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->termmeta WHERE term_id = %d ", $term ) );
    17671804        foreach ( $term_meta_ids as $mid ) {
     
    17881825        do_action( 'deleted_term_taxonomy', $tt_id );
    17891826
    17901827        // Delete the term if no taxonomies use it.
    1791         if ( !$wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_taxonomy WHERE term_id = %d", $term) ) )
     1828        if ( ! $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_taxonomy WHERE term_id = %d", $term ) ) ) {
    17921829                $wpdb->delete( $wpdb->terms, array( 'term_id' => $term ) );
     1830        }
    17931831
    1794         clean_term_cache($term, $taxonomy);
     1832        clean_term_cache( $term, $taxonomy );
    17951833
    17961834        /**
    17971835         * Fires after a term is deleted from the database and the cache is cleaned.
     
    18591897 * @return array|WP_Error The requested term data or empty array if no terms found.
    18601898 *                        WP_Error if any of the $taxonomies don't exist.
    18611899 */
    1862 function wp_get_object_terms($object_ids, $taxonomies, $args = array()) {
     1900function wp_get_object_terms( $object_ids, $taxonomies, $args = array() ) {
    18631901        global $wpdb;
    18641902
    1865         if ( empty( $object_ids ) || empty( $taxonomies ) )
     1903        if ( empty( $object_ids ) || empty( $taxonomies ) ) {
    18661904                return array();
     1905        }
    18671906
    1868         if ( !is_array($taxonomies) )
    1869                 $taxonomies = array($taxonomies);
     1907        if ( ! is_array( $taxonomies ) ) {
     1908                $taxonomies = array( $taxonomies );
     1909        }
    18701910
    18711911        foreach ( $taxonomies as $taxonomy ) {
    1872                 if ( ! taxonomy_exists($taxonomy) )
     1912                if ( ! taxonomy_exists( $taxonomy ) ) {
    18731913                        return new WP_Error( 'invalid_taxonomy', __( 'Invalid taxonomy.' ) );
     1914                }
    18741915        }
    18751916
    1876         if ( !is_array($object_ids) )
    1877                 $object_ids = array($object_ids);
    1878         $object_ids = array_map('intval', $object_ids);
     1917        if ( ! is_array( $object_ids ) ) {
     1918                $object_ids = array( $object_ids );
     1919        }
     1920        $object_ids = array_map( 'intval', $object_ids );
    18791921
    18801922        $args = wp_parse_args( $args );
    18811923
     
    19632005function wp_insert_term( $term, $taxonomy, $args = array() ) {
    19642006        global $wpdb;
    19652007
    1966         if ( ! taxonomy_exists($taxonomy) ) {
     2008        if ( ! taxonomy_exists( $taxonomy ) ) {
    19672009                return new WP_Error( 'invalid_taxonomy', __( 'Invalid taxonomy.' ) );
    19682010        }
    19692011        /**
     
    19842026        if ( '' == trim( $term ) ) {
    19852027                return new WP_Error( 'empty_term_name', __( 'A name is required for this term.' ) );
    19862028        }
    1987         $defaults = array( 'alias_of' => '', 'description' => '', 'parent' => 0, 'slug' => '');
     2029        $defaults = array( 'alias_of' => '', 'description' => '', 'parent' => 0, 'slug' => '' );
    19882030        $args = wp_parse_args( $args, $defaults );
    19892031
    19902032        if ( $args['parent'] > 0 && ! term_exists( (int) $args['parent'] ) ) {
     
    19972039        // Coerce null description to strings, to avoid database errors.
    19982040        $args['description'] = (string) $args['description'];
    19992041
    2000         $args = sanitize_term($args, $taxonomy, 'db');
     2042        $args = sanitize_term( $args, $taxonomy, 'db' );
    20012043
    20022044        // expected_slashed ($name)
    20032045        $name = wp_unslash( $args['name'] );
     
    20222064                         * The alias is not in a group, so we create a new one
    20232065                         * and add the alias to it.
    20242066                         */
    2025                         $term_group = $wpdb->get_var("SELECT MAX(term_group) FROM $wpdb->terms") + 1;
     2067                        $term_group = $wpdb->get_var( "SELECT MAX(term_group) FROM $wpdb->terms" ) + 1;
    20262068
    20272069                        wp_update_term( $alias->term_id, $taxonomy, array(
    20282070                                'term_group' => $term_group,
     
    20972139        $term_id = (int) $wpdb->insert_id;
    20982140
    20992141        // Seems unreachable, However, Is used in the case that a term name is provided, which sanitizes to an empty string.
    2100         if ( empty($slug) ) {
    2101                 $slug = sanitize_title($slug, $term_id);
     2142        if ( empty( $slug ) ) {
     2143                $slug = sanitize_title( $slug, $term_id );
    21022144
    21032145                /** This action is documented in wp-includes/taxonomy.php */
    21042146                do_action( 'edit_terms', $term_id, $taxonomy );
     
    21102152
    21112153        $tt_id = $wpdb->get_var( $wpdb->prepare( "SELECT tt.term_taxonomy_id FROM $wpdb->term_taxonomy AS tt INNER JOIN $wpdb->terms AS t ON tt.term_id = t.term_id WHERE tt.taxonomy = %s AND t.term_id = %d", $taxonomy, $term_id ) );
    21122154
    2113         if ( !empty($tt_id) ) {
    2114                 return array('term_id' => $term_id, 'term_taxonomy_id' => $tt_id);
     2155        if ( ! empty( $tt_id ) ) {
     2156                return array( 'term_id' => $term_id, 'term_taxonomy_id' => $tt_id );
    21152157        }
    2116         $wpdb->insert( $wpdb->term_taxonomy, compact( 'term_id', 'taxonomy', 'description', 'parent') + array( 'count' => 0 ) );
     2158        $wpdb->insert( $wpdb->term_taxonomy, compact( 'term_id', 'taxonomy', 'description', 'parent' ) + array( 'count' => 0 ) );
    21172159        $tt_id = (int) $wpdb->insert_id;
    21182160
    21192161        /*
     
    21432185         * @param int    $tt_id    Term taxonomy ID.
    21442186         * @param string $taxonomy Taxonomy slug.
    21452187         */
    2146         do_action( "create_term", $term_id, $tt_id, $taxonomy );
     2188        do_action( 'create_term', $term_id, $tt_id, $taxonomy );
    21472189
    21482190        /**
    21492191         * Fires after a new term is created for a specific taxonomy.
     
    21682210         */
    21692211        $term_id = apply_filters( 'term_id_filter', $term_id, $tt_id );
    21702212
    2171         clean_term_cache($term_id, $taxonomy);
     2213        clean_term_cache( $term_id, $taxonomy );
    21722214
    21732215        /**
    21742216         * Fires after a new term is created, and after the term cache has been cleaned.
     
    21942236         */
    21952237        do_action( "created_{$taxonomy}", $term_id, $tt_id );
    21962238
    2197         return array('term_id' => $term_id, 'term_taxonomy_id' => $tt_id);
     2239        return array( 'term_id' => $term_id, 'term_taxonomy_id' => $tt_id );
    21982240}
    21992241
    22002242/**
     
    22292271                return new WP_Error( 'invalid_taxonomy', __( 'Invalid taxonomy.' ) );
    22302272        }
    22312273
    2232         if ( !is_array($terms) )
    2233                 $terms = array($terms);
     2274        if ( ! is_array( $terms ) ) {
     2275                $terms = array( $terms );
     2276        }
    22342277
    2235         if ( ! $append )
    2236                 $old_tt_ids =  wp_get_object_terms($object_id, $taxonomy, array('fields' => 'tt_ids', 'orderby' => 'none'));
    2237         else
    2238                 $old_tt_ids = array();
     2278        if ( ! $append ) {
     2279                $old_tt_ids = wp_get_object_terms( $object_id, $taxonomy, array( 'fields' => 'tt_ids', 'orderby' => 'none' ) );
     2280        } else { $old_tt_ids = array();
     2281        }
    22392282
    22402283        $tt_ids = array();
    22412284        $term_ids = array();
    22422285        $new_tt_ids = array();
    22432286
    2244         foreach ( (array) $terms as $term) {
    2245                 if ( !strlen(trim($term)) )
     2287        foreach ( (array) $terms as $term ) {
     2288                if ( ! strlen( trim( $term ) ) ) {
    22462289                        continue;
     2290                }
    22472291
    2248                 if ( !$term_info = term_exists($term, $taxonomy) ) {
     2292                if ( ! $term_info = term_exists( $term, $taxonomy ) ) {
    22492293                        // Skip if a non-existent term ID is passed.
    2250                         if ( is_int($term) )
     2294                        if ( is_int( $term ) ) {
    22512295                                continue;
    2252                         $term_info = wp_insert_term($term, $taxonomy);
     2296                        }
     2297                        $term_info = wp_insert_term( $term, $taxonomy );
    22532298                }
    2254                 if ( is_wp_error($term_info) )
     2299                if ( is_wp_error( $term_info ) ) {
    22552300                        return $term_info;
     2301                }
    22562302                $term_ids[] = $term_info['term_id'];
    22572303                $tt_id = $term_info['term_taxonomy_id'];
    22582304                $tt_ids[] = $tt_id;
    22592305
    2260                 if ( $wpdb->get_var( $wpdb->prepare( "SELECT term_taxonomy_id FROM $wpdb->term_relationships WHERE object_id = %d AND term_taxonomy_id = %d", $object_id, $tt_id ) ) )
     2306                if ( $wpdb->get_var( $wpdb->prepare( "SELECT term_taxonomy_id FROM $wpdb->term_relationships WHERE object_id = %d AND term_taxonomy_id = %d", $object_id, $tt_id ) ) ) {
    22612307                        continue;
     2308                }
    22622309
    22632310                /**
    22642311                 * Fires immediately before an object-term relationship is added.
     
    22872334                $new_tt_ids[] = $tt_id;
    22882335        }
    22892336
    2290         if ( $new_tt_ids )
     2337        if ( $new_tt_ids ) {
    22912338                wp_update_term_count( $new_tt_ids, $taxonomy );
     2339        }
    22922340
    22932341        if ( ! $append ) {
    22942342                $delete_tt_ids = array_diff( $old_tt_ids, $tt_ids );
     
    23052353                }
    23062354        }
    23072355
    2308         $t = get_taxonomy($taxonomy);
    2309         if ( ! $append && isset($t->sort) && $t->sort ) {
     2356        $t = get_taxonomy( $taxonomy );
     2357        if ( ! $append && isset( $t->sort ) && $t->sort ) {
    23102358                $values = array();
    23112359                $term_order = 0;
    2312                 $final_tt_ids = wp_get_object_terms($object_id, $taxonomy, array('fields' => 'tt_ids'));
    2313                 foreach ( $tt_ids as $tt_id )
    2314                         if ( in_array($tt_id, $final_tt_ids) )
    2315                                 $values[] = $wpdb->prepare( "(%d, %d, %d)", $object_id, $tt_id, ++$term_order);
    2316                 if ( $values )
    2317                         if ( false === $wpdb->query( "INSERT INTO $wpdb->term_relationships (object_id, term_taxonomy_id, term_order) VALUES " . join( ',', $values ) . " ON DUPLICATE KEY UPDATE term_order = VALUES(term_order)" ) )
     2360                $final_tt_ids = wp_get_object_terms( $object_id, $taxonomy, array( 'fields' => 'tt_ids' ) );
     2361                foreach ( $tt_ids as $tt_id ) {
     2362                        if ( in_array( $tt_id, $final_tt_ids ) ) {
     2363                                $values[] = $wpdb->prepare( '(%d, %d, %d)', $object_id, $tt_id, ++$term_order );
     2364                        }
     2365                }
     2366                if ( $values ) {
     2367                        if ( false === $wpdb->query( "INSERT INTO $wpdb->term_relationships (object_id, term_taxonomy_id, term_order) VALUES " . join( ',', $values ) . ' ON DUPLICATE KEY UPDATE term_order = VALUES(term_order)' ) ) {
    23182368                                return new WP_Error( 'db_insert_error', __( 'Could not insert term relationship into the database' ), $wpdb->last_error );
     2369                        }
     2370                }
    23192371        }
    23202372
    23212373        wp_cache_delete( $object_id, $taxonomy . '_relationships' );
     
    24752527        $parent_suffix = '';
    24762528        if ( $needs_suffix && is_taxonomy_hierarchical( $term->taxonomy ) && ! empty( $term->parent ) ) {
    24772529                $the_parent = $term->parent;
    2478                 while ( ! empty($the_parent) ) {
    2479                         $parent_term = get_term($the_parent, $term->taxonomy);
    2480                         if ( is_wp_error($parent_term) || empty($parent_term) )
     2530                while ( ! empty( $the_parent ) ) {
     2531                        $parent_term = get_term( $the_parent, $term->taxonomy );
     2532                        if ( is_wp_error( $parent_term ) || empty( $parent_term ) ) {
    24812533                                break;
     2534                        }
    24822535                        $parent_suffix .= '-' . $parent_term->slug;
    24832536                        if ( ! term_exists( $slug . $parent_suffix ) ) {
    24842537                                break;
    24852538                        }
    24862539
    2487                         if ( empty($parent_term->parent) )
     2540                        if ( empty( $parent_term->parent ) ) {
    24882541                                break;
     2542                        }
    24892543                        $the_parent = $parent_term->parent;
    24902544                }
    24912545        }
     
    25052559                if ( $parent_suffix ) {
    25062560                        $slug .= $parent_suffix;
    25072561                } else {
    2508                         if ( ! empty( $term->term_id ) )
     2562                        if ( ! empty( $term->term_id ) ) {
    25092563                                $query = $wpdb->prepare( "SELECT slug FROM $wpdb->terms WHERE slug = %s AND term_id != %d", $slug, $term->term_id );
    2510                         else
    2511                                 $query = $wpdb->prepare( "SELECT slug FROM $wpdb->terms WHERE slug = %s", $slug );
     2564                        } else { $query = $wpdb->prepare( "SELECT slug FROM $wpdb->terms WHERE slug = %s", $slug );
     2565                        }
    25122566
    25132567                        if ( $wpdb->get_var( $query ) ) {
    25142568                                $num = 2;
     
    25902644        $term = wp_slash( $term );
    25912645
    25922646        // Merge old and new args with new args overwriting old ones.
    2593         $args = array_merge($term, $args);
     2647        $args = array_merge( $term, $args );
    25942648
    2595         $defaults = array( 'alias_of' => '', 'description' => '', 'parent' => 0, 'slug' => '');
    2596         $args = wp_parse_args($args, $defaults);
    2597         $args = sanitize_term($args, $taxonomy, 'db');
     2649        $defaults = array( 'alias_of' => '', 'description' => '', 'parent' => 0, 'slug' => '' );
     2650        $args = wp_parse_args( $args, $defaults );
     2651        $args = sanitize_term( $args, $taxonomy, 'db' );
    25982652        $parsed_args = $args;
    25992653
    26002654        // expected_slashed ($name)
     
    26152669        $empty_slug = false;
    26162670        if ( empty( $args['slug'] ) ) {
    26172671                $empty_slug = true;
    2618                 $slug = sanitize_title($name);
     2672                $slug = sanitize_title( $name );
    26192673        } else {
    26202674                $slug = $args['slug'];
    26212675        }
     
    26332687                         * The alias is not in a group, so we create a new one
    26342688                         * and add the alias to it.
    26352689                         */
    2636                         $term_group = $wpdb->get_var("SELECT MAX(term_group) FROM $wpdb->terms") + 1;
     2690                        $term_group = $wpdb->get_var( "SELECT MAX(term_group) FROM $wpdb->terms" ) + 1;
    26372691
    26382692                        wp_update_term( $alias->term_id, $taxonomy, array(
    26392693                                'term_group' => $term_group,
     
    26642718                // If an empty slug was passed or the parent changed, reset the slug to something unique.
    26652719                // Otherwise, bail.
    26662720                if ( $empty_slug || ( $parent != $term['parent']) ) {
    2667                         $slug = wp_unique_term_slug($slug, (object) $args);
     2721                        $slug = wp_unique_term_slug( $slug, (object) $args );
    26682722                } else {
    26692723                        /* translators: 1: Taxonomy term slug */
    2670                         return new WP_Error('duplicate_term_slug', sprintf(__('The slug &#8220;%s&#8221; is already in use by another term'), $slug));
     2724                        return new WP_Error( 'duplicate_term_slug', sprintf( __( 'The slug &#8220;%s&#8221; is already in use by another term' ), $slug ) );
    26712725                }
    26722726        }
    26732727
    2674         $tt_id = (int) $wpdb->get_var( $wpdb->prepare( "SELECT tt.term_taxonomy_id FROM $wpdb->term_taxonomy AS tt INNER JOIN $wpdb->terms AS t ON tt.term_id = t.term_id WHERE tt.taxonomy = %s AND t.term_id = %d", $taxonomy, $term_id) );
     2728        $tt_id = (int) $wpdb->get_var( $wpdb->prepare( "SELECT tt.term_taxonomy_id FROM $wpdb->term_taxonomy AS tt INNER JOIN $wpdb->terms AS t ON tt.term_id = t.term_id WHERE tt.taxonomy = %s AND t.term_id = %d", $taxonomy, $term_id ) );
    26752729
    26762730        // Check whether this is a shared term that needs splitting.
    26772731        $_term_id = _split_shared_term( $term_id, $tt_id );
     
    27042758        $data = apply_filters( 'wp_update_term_data', $data, $term_id, $taxonomy, $args );
    27052759
    27062760        $wpdb->update( $wpdb->terms, $data, compact( 'term_id' ) );
    2707         if ( empty($slug) ) {
    2708                 $slug = sanitize_title($name, $term_id);
     2761        if ( empty( $slug ) ) {
     2762                $slug = sanitize_title( $name, $term_id );
    27092763                $wpdb->update( $wpdb->terms, compact( 'slug' ), compact( 'term_id' ) );
    27102764        }
    27112765
     
    27502804         * @param int    $tt_id    Term taxonomy ID.
    27512805         * @param string $taxonomy Taxonomy slug.
    27522806         */
    2753         do_action( "edit_term", $term_id, $tt_id, $taxonomy );
     2807        do_action( 'edit_term', $term_id, $tt_id, $taxonomy );
    27542808
    27552809        /**
    27562810         * Fires after a term in a specific taxonomy has been updated, but before the term
     
    27682822        /** This filter is documented in wp-includes/taxonomy.php */
    27692823        $term_id = apply_filters( 'term_id_filter', $term_id, $tt_id );
    27702824
    2771         clean_term_cache($term_id, $taxonomy);
     2825        clean_term_cache( $term_id, $taxonomy );
    27722826
    27732827        /**
    27742828         * Fires after a term has been updated, and the term cache has been cleaned.
     
    27792833         * @param int    $tt_id    Term taxonomy ID.
    27802834         * @param string $taxonomy Taxonomy slug.
    27812835         */
    2782         do_action( "edited_term", $term_id, $tt_id, $taxonomy );
     2836        do_action( 'edited_term', $term_id, $tt_id, $taxonomy );
    27832837
    27842838        /**
    27852839         * Fires after a term for a specific taxonomy has been updated, and the term
     
    27942848         */
    27952849        do_action( "edited_{$taxonomy}", $term_id, $tt_id );
    27962850
    2797         return array('term_id' => $term_id, 'term_taxonomy_id' => $tt_id);
     2851        return array( 'term_id' => $term_id, 'term_taxonomy_id' => $tt_id );
    27982852}
    27992853
    28002854/**
     
    28072861 * @param bool $defer Optional. Enable if true, disable if false.
    28082862 * @return bool Whether term counting is enabled or disabled.
    28092863 */
    2810 function wp_defer_term_counting($defer=null) {
     2864function wp_defer_term_counting( $defer = null ) {
    28112865        static $_defer = false;
    28122866
    2813         if ( is_bool($defer) ) {
     2867        if ( is_bool( $defer ) ) {
    28142868                $_defer = $defer;
    28152869                // flush any deferred counts
    2816                 if ( !$defer )
     2870                if ( ! $defer ) {
    28172871                        wp_update_term_count( null, null, true );
     2872                }
    28182873        }
    28192874
    28202875        return $_defer;
     
    28422897        static $_deferred = array();
    28432898
    28442899        if ( $do_deferred ) {
    2845                 foreach ( (array) array_keys($_deferred) as $tax ) {
    2846                         wp_update_term_count_now( $_deferred[$tax], $tax );
    2847                         unset( $_deferred[$tax] );
     2900                foreach ( (array) array_keys( $_deferred ) as $tax ) {
     2901                        wp_update_term_count_now( $_deferred[ $tax ], $tax );
     2902                        unset( $_deferred[ $tax ] );
    28482903                }
    28492904        }
    28502905
    2851         if ( empty($terms) )
     2906        if ( empty( $terms ) ) {
    28522907                return false;
     2908        }
    28532909
    2854         if ( !is_array($terms) )
    2855                 $terms = array($terms);
     2910        if ( ! is_array( $terms ) ) {
     2911                $terms = array( $terms );
     2912        }
    28562913
    28572914        if ( wp_defer_term_counting() ) {
    2858                 if ( !isset($_deferred[$taxonomy]) )
    2859                         $_deferred[$taxonomy] = array();
    2860                 $_deferred[$taxonomy] = array_unique( array_merge($_deferred[$taxonomy], $terms) );
     2915                if ( ! isset( $_deferred[ $taxonomy ] ) ) {
     2916                        $_deferred[ $taxonomy ] = array();
     2917                }
     2918                $_deferred[ $taxonomy ] = array_unique( array_merge( $_deferred[ $taxonomy ], $terms ) );
    28612919                return true;
    28622920        }
    28632921
     
    28742932 * @return true Always true when complete.
    28752933 */
    28762934function wp_update_term_count_now( $terms, $taxonomy ) {
    2877         $terms = array_map('intval', $terms);
     2935        $terms = array_map( 'intval', $terms );
    28782936
    2879         $taxonomy = get_taxonomy($taxonomy);
    2880         if ( !empty($taxonomy->update_count_callback) ) {
    2881                 call_user_func($taxonomy->update_count_callback, $terms, $taxonomy);
     2937        $taxonomy = get_taxonomy( $taxonomy );
     2938        if ( ! empty( $taxonomy->update_count_callback ) ) {
     2939                call_user_func( $taxonomy->update_count_callback, $terms, $taxonomy );
    28822940        } else {
    28832941                $object_types = (array) $taxonomy->object_type;
    28842942                foreach ( $object_types as &$object_type ) {
    2885                         if ( 0 === strpos( $object_type, 'attachment:' ) )
     2943                        if ( 0 === strpos( $object_type, 'attachment:' ) ) {
    28862944                                list( $object_type ) = explode( ':', $object_type );
     2945                        }
    28872946                }
    28882947
    28892948                if ( $object_types == array_filter( $object_types, 'post_type_exists' ) ) {
     
    28952954                }
    28962955        }
    28972956
    2898         clean_term_cache($terms, '', false);
     2957        clean_term_cache( $terms, '', false );
    28992958
    29002959        return true;
    29012960}
     
    29202979 * @param int|array    $object_ids  Single or list of term object ID(s).
    29212980 * @param array|string $object_type The taxonomy object type.
    29222981 */
    2923 function clean_object_term_cache($object_ids, $object_type) {
     2982function clean_object_term_cache( $object_ids, $object_type ) {
    29242983        global $_wp_suspend_cache_invalidation;
    29252984
    29262985        if ( ! empty( $_wp_suspend_cache_invalidation ) ) {
     
    29272986                return;
    29282987        }
    29292988
    2930         if ( !is_array($object_ids) )
    2931                 $object_ids = array($object_ids);
     2989        if ( ! is_array( $object_ids ) ) {
     2990                $object_ids = array( $object_ids );
     2991        }
    29322992
    29332993        $taxonomies = get_object_taxonomies( $object_type );
    29342994
    29352995        foreach ( $object_ids as $id ) {
    29362996                foreach ( $taxonomies as $taxonomy ) {
    2937                         wp_cache_delete($id, "{$taxonomy}_relationships");
     2997                        wp_cache_delete( $id, "{$taxonomy}_relationships" );
    29382998                }
    29392999        }
    29403000
     
    29633023 * @param bool      $clean_taxonomy Optional. Whether to clean taxonomy wide caches (true), or just individual
    29643024 *                                  term object caches (false). Default true.
    29653025 */
    2966 function clean_term_cache($ids, $taxonomy = '', $clean_taxonomy = true) {
     3026function clean_term_cache( $ids, $taxonomy = '', $clean_taxonomy = true ) {
    29673027        global $wpdb, $_wp_suspend_cache_invalidation;
    29683028
    29693029        if ( ! empty( $_wp_suspend_cache_invalidation ) ) {
     
    29703030                return;
    29713031        }
    29723032
    2973         if ( !is_array($ids) )
    2974                 $ids = array($ids);
     3033        if ( ! is_array( $ids ) ) {
     3034                $ids = array( $ids );
     3035        }
    29753036
    29763037        $taxonomies = array();
    29773038        // If no taxonomy, assume tt_ids.
    2978         if ( empty($taxonomy) ) {
    2979                 $tt_ids = array_map('intval', $ids);
    2980                 $tt_ids = implode(', ', $tt_ids);
    2981                 $terms = $wpdb->get_results("SELECT term_id, taxonomy FROM $wpdb->term_taxonomy WHERE term_taxonomy_id IN ($tt_ids)");
     3039        if ( empty( $taxonomy ) ) {
     3040                $tt_ids = array_map( 'intval', $ids );
     3041                $tt_ids = implode( ', ', $tt_ids );
     3042                $terms = $wpdb->get_results( "SELECT term_id, taxonomy FROM $wpdb->term_taxonomy WHERE term_taxonomy_id IN ($tt_ids)" );
    29823043                $ids = array();
    29833044                foreach ( (array) $terms as $term ) {
    29843045                        $taxonomies[] = $term->taxonomy;
     
    29853046                        $ids[] = $term->term_id;
    29863047                        wp_cache_delete( $term->term_id, 'terms' );
    29873048                }
    2988                 $taxonomies = array_unique($taxonomies);
     3049                $taxonomies = array_unique( $taxonomies );
    29893050        } else {
    2990                 $taxonomies = array($taxonomy);
     3051                $taxonomies = array( $taxonomy );
    29913052                foreach ( $taxonomies as $taxonomy ) {
    29923053                        foreach ( $ids as $id ) {
    29933054                                wp_cache_delete( $id, 'terms' );
     
    29973058
    29983059        foreach ( $taxonomies as $taxonomy ) {
    29993060                if ( $clean_taxonomy ) {
    3000                         wp_cache_delete('all_ids', $taxonomy);
    3001                         wp_cache_delete('get', $taxonomy);
    3002                         delete_option("{$taxonomy}_children");
     3061                        wp_cache_delete( 'all_ids', $taxonomy );
     3062                        wp_cache_delete( 'get', $taxonomy );
     3063                        delete_option( "{$taxonomy}_children" );
    30033064                        // Regenerate {$taxonomy}_children
    3004                         _get_term_hierarchy($taxonomy);
     3065                        _get_term_hierarchy( $taxonomy );
    30053066                }
    30063067
    30073068                /**
     
    30873148 * @param array|string $object_type The taxonomy object type.
    30883149 * @return void|false False if all of the terms in `$object_ids` are already cached.
    30893150 */
    3090 function update_object_term_cache($object_ids, $object_type) {
    3091         if ( empty($object_ids) )
     3151function update_object_term_cache( $object_ids, $object_type ) {
     3152        if ( empty( $object_ids ) ) {
    30923153                return;
     3154        }
    30933155
    3094         if ( !is_array($object_ids) )
    3095                 $object_ids = explode(',', $object_ids);
     3156        if ( ! is_array( $object_ids ) ) {
     3157                $object_ids = explode( ',', $object_ids );
     3158        }
    30963159
    3097         $object_ids = array_map('intval', $object_ids);
     3160        $object_ids = array_map( 'intval', $object_ids );
    30983161
    3099         $taxonomies = get_object_taxonomies($object_type);
     3162        $taxonomies = get_object_taxonomies( $object_type );
    31003163
    31013164        $ids = array();
    31023165        foreach ( (array) $object_ids as $id ) {
    31033166                foreach ( $taxonomies as $taxonomy ) {
    3104                         if ( false === wp_cache_get($id, "{$taxonomy}_relationships") ) {
     3167                        if ( false === wp_cache_get( $id, "{$taxonomy}_relationships" ) ) {
    31053168                                $ids[] = $id;
    31063169                                break;
    31073170                        }
     
    31083171                }
    31093172        }
    31103173
    3111         if ( empty( $ids ) )
     3174        if ( empty( $ids ) ) {
    31123175                return false;
     3176        }
    31133177
    31143178        $terms = wp_get_object_terms( $ids, $taxonomies, array(
    31153179                'fields' => 'all_with_object_id',
     
    31243188
    31253189        foreach ( $ids as $id ) {
    31263190                foreach ( $taxonomies as $taxonomy ) {
    3127                         if ( ! isset($object_terms[$id][$taxonomy]) ) {
    3128                                 if ( !isset($object_terms[$id]) )
    3129                                         $object_terms[$id] = array();
    3130                                 $object_terms[$id][$taxonomy] = array();
     3191                        if ( ! isset( $object_terms[ $id ][ $taxonomy ] ) ) {
     3192                                if ( ! isset( $object_terms[ $id ] ) ) {
     3193                                        $object_terms[ $id ] = array();
     3194                                }
     3195                                $object_terms[ $id ][ $taxonomy ] = array();
    31313196                        }
    31323197                }
    31333198        }
     
    31733238 * @return array Empty if $taxonomy isn't hierarchical or returns children as Term IDs.
    31743239 */
    31753240function _get_term_hierarchy( $taxonomy ) {
    3176         if ( !is_taxonomy_hierarchical($taxonomy) )
     3241        if ( ! is_taxonomy_hierarchical( $taxonomy ) ) {
    31773242                return array();
    3178         $children = get_option("{$taxonomy}_children");
     3243        }
     3244        $children = get_option( "{$taxonomy}_children" );
    31793245
    3180         if ( is_array($children) )
     3246        if ( is_array( $children ) ) {
    31813247                return $children;
     3248        }
    31823249        $children = array();
    3183         $terms = get_terms($taxonomy, array('get' => 'all', 'orderby' => 'id', 'fields' => 'id=>parent'));
     3250        $terms = get_terms( $taxonomy, array( 'get' => 'all', 'orderby' => 'id', 'fields' => 'id=>parent' ) );
    31843251        foreach ( $terms as $term_id => $parent ) {
    3185                 if ( $parent > 0 )
    3186                         $children[$parent][] = $term_id;
     3252                if ( $parent > 0 ) {
     3253                        $children[ $parent ][] = $term_id;
     3254                }
    31873255        }
    3188         update_option("{$taxonomy}_children", $children);
     3256        update_option( "{$taxonomy}_children", $children );
    31893257
    31903258        return $children;
    31913259}
     
    32113279 */
    32123280function _get_term_children( $term_id, $terms, $taxonomy, &$ancestors = array() ) {
    32133281        $empty_array = array();
    3214         if ( empty($terms) )
     3282        if ( empty( $terms ) ) {
    32153283                return $empty_array;
     3284        }
    32163285
    32173286        $term_list = array();
    3218         $has_children = _get_term_hierarchy($taxonomy);
     3287        $has_children = _get_term_hierarchy( $taxonomy );
    32193288
    3220         if  ( ( 0 != $term_id ) && ! isset($has_children[$term_id]) )
     3289        if ( ( 0 != $term_id ) && ! isset( $has_children[ $term_id ] ) ) {
    32213290                return $empty_array;
     3291        }
    32223292
    32233293        // Include the term itself in the ancestors array, so we can properly detect when a loop has occurred.
    32243294        if ( empty( $ancestors ) ) {
     
    32273297
    32283298        foreach ( (array) $terms as $term ) {
    32293299                $use_id = false;
    3230                 if ( !is_object($term) ) {
    3231                         $term = get_term($term, $taxonomy);
    3232                         if ( is_wp_error( $term ) )
     3300                if ( ! is_object( $term ) ) {
     3301                        $term = get_term( $term, $taxonomy );
     3302                        if ( is_wp_error( $term ) ) {
    32333303                                return $term;
     3304                        }
    32343305                        $use_id = true;
    32353306                }
    32363307
     
    32403311                }
    32413312
    32423313                if ( $term->parent == $term_id ) {
    3243                         if ( $use_id )
     3314                        if ( $use_id ) {
    32443315                                $term_list[] = $term->term_id;
    3245                         else
    3246                                 $term_list[] = $term;
     3316                        } else { $term_list[] = $term;
     3317                        }
    32473318
    3248                         if ( !isset($has_children[$term->term_id]) )
     3319                        if ( ! isset( $has_children[ $term->term_id ] ) ) {
    32493320                                continue;
     3321                        }
    32503322
    32513323                        $ancestors[ $term->term_id ] = 1;
    32523324
    3253                         if ( $children = _get_term_children( $term->term_id, $terms, $taxonomy, $ancestors) )
    3254                                 $term_list = array_merge($term_list, $children);
     3325                        if ( $children = _get_term_children( $term->term_id, $terms, $taxonomy, $ancestors ) ) {
     3326                                $term_list = array_merge( $term_list, $children );
     3327                        }
    32553328                }
    32563329        }
    32573330
     
    32763349        global $wpdb;
    32773350
    32783351        // This function only works for hierarchical taxonomies like post categories.
    3279         if ( !is_taxonomy_hierarchical( $taxonomy ) )
     3352        if ( ! is_taxonomy_hierarchical( $taxonomy ) ) {
    32803353                return;
     3354        }
    32813355
    3282         $term_hier = _get_term_hierarchy($taxonomy);
     3356        $term_hier = _get_term_hierarchy( $taxonomy );
    32833357
    3284         if ( empty($term_hier) )
     3358        if ( empty( $term_hier ) ) {
    32853359                return;
     3360        }
    32863361
    32873362        $term_items = array();
    32883363        $terms_by_id = array();
     
    32893364        $term_ids = array();
    32903365
    32913366        foreach ( (array) $terms as $key => $term ) {
    3292                 $terms_by_id[$term->term_id] = & $terms[$key];
    3293                 $term_ids[$term->term_taxonomy_id] = $term->term_id;
     3367                $terms_by_id[ $term->term_id ] = & $terms[ $key ];
     3368                $term_ids[ $term->term_taxonomy_id ] = $term->term_id;
    32943369        }
    32953370
    32963371        // Get the object and term ids and stick them in a lookup table.
    3297         $tax_obj = get_taxonomy($taxonomy);
    3298         $object_types = esc_sql($tax_obj->object_type);
    3299         $results = $wpdb->get_results("SELECT object_id, term_taxonomy_id FROM $wpdb->term_relationships INNER JOIN $wpdb->posts ON object_id = ID WHERE term_taxonomy_id IN (" . implode(',', array_keys($term_ids)) . ") AND post_type IN ('" . implode("', '", $object_types) . "') AND post_status = 'publish'");
     3372        $tax_obj = get_taxonomy( $taxonomy );
     3373        $object_types = esc_sql( $tax_obj->object_type );
     3374        $results = $wpdb->get_results( "SELECT object_id, term_taxonomy_id FROM $wpdb->term_relationships INNER JOIN $wpdb->posts ON object_id = ID WHERE term_taxonomy_id IN (" . implode( ',', array_keys( $term_ids ) ) . ") AND post_type IN ('" . implode( "', '", $object_types ) . "') AND post_status = 'publish'" );
    33003375        foreach ( $results as $row ) {
    3301                 $id = $term_ids[$row->term_taxonomy_id];
    3302                 $term_items[$id][$row->object_id] = isset($term_items[$id][$row->object_id]) ? ++$term_items[$id][$row->object_id] : 1;
     3376                $id = $term_ids[ $row->term_taxonomy_id ];
     3377                $term_items[ $id ][ $row->object_id ] = isset( $term_items[ $id ][ $row->object_id ] ) ? ++$term_items[ $id ][ $row->object_id ] : 1;
    33033378        }
    33043379
    33053380        // Touch every ancestor's lookup row for each post in each term.
     
    33063381        foreach ( $term_ids as $term_id ) {
    33073382                $child = $term_id;
    33083383                $ancestors = array();
    3309                 while ( !empty( $terms_by_id[$child] ) && $parent = $terms_by_id[$child]->parent ) {
     3384                while ( ! empty( $terms_by_id[ $child ] ) && $parent = $terms_by_id[ $child ]->parent ) {
    33103385                        $ancestors[] = $child;
    3311                         if ( !empty( $term_items[$term_id] ) )
    3312                                 foreach ( $term_items[$term_id] as $item_id => $touches ) {
    3313                                         $term_items[$parent][$item_id] = isset($term_items[$parent][$item_id]) ? ++$term_items[$parent][$item_id]: 1;
     3386                        if ( ! empty( $term_items[ $term_id ] ) ) {
     3387                                foreach ( $term_items[ $term_id ] as $item_id => $touches ) {
     3388                                        $term_items[ $parent ][ $item_id ] = isset( $term_items[ $parent ][ $item_id ] ) ? ++$term_items[ $parent ][ $item_id ]: 1;
    33143389                                }
     3390                        }
    33153391                        $child = $parent;
    33163392
    33173393                        if ( in_array( $parent, $ancestors ) ) {
     
    33213397        }
    33223398
    33233399        // Transfer the touched cells.
    3324         foreach ( (array) $term_items as $id => $items )
    3325                 if ( isset($terms_by_id[$id]) )
    3326                         $terms_by_id[$id]->count = count($items);
     3400        foreach ( (array) $term_items as $id => $items ) {
     3401                if ( isset( $terms_by_id[ $id ] ) ) {
     3402                        $terms_by_id[ $id ]->count = count( $items );
     3403                }
     3404        }
    33273405}
    33283406
    33293407/**
     
    33423420
    33433421        $non_cached_ids = _get_non_cached_ids( $term_ids, 'terms' );
    33443422        if ( ! empty( $non_cached_ids ) ) {
    3345                 $fresh_terms = $wpdb->get_results( sprintf( "SELECT t.*, tt.* FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE t.term_id IN (%s)", join( ",", array_map( 'intval', $non_cached_ids ) ) ) );
     3423                $fresh_terms = $wpdb->get_results( sprintf( "SELECT t.*, tt.* FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE t.term_id IN (%s)", join( ',', array_map( 'intval', $non_cached_ids ) ) ) );
    33463424
    33473425                update_term_cache( $fresh_terms, $update_meta_cache );
    33483426
     
    33753453
    33763454        $object_types = (array) $taxonomy->object_type;
    33773455
    3378         foreach ( $object_types as &$object_type )
     3456        foreach ( $object_types as &$object_type ) {
    33793457                list( $object_type ) = explode( ':', $object_type );
     3458        }
    33803459
    33813460        $object_types = array_unique( $object_types );
    33823461
     
    33853464                $check_attachments = true;
    33863465        }
    33873466
    3388         if ( $object_types )
     3467        if ( $object_types ) {
    33893468                $object_types = esc_sql( array_filter( $object_types, 'post_type_exists' ) );
     3469        }
    33903470
    33913471        foreach ( (array) $terms as $term ) {
    33923472                $count = 0;
    33933473
    33943474                // Attachments can be 'inherit' status, we need to base count off the parent's status if so.
    3395                 if ( $check_attachments )
     3475                if ( $check_attachments ) {
    33963476                        $count += (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_relationships, $wpdb->posts p1 WHERE p1.ID = $wpdb->term_relationships.object_id AND ( post_status = 'publish' OR ( post_status = 'inherit' AND post_parent > 0 AND ( SELECT post_status FROM $wpdb->posts WHERE ID = p1.post_parent ) = 'publish' ) ) AND post_type = 'attachment' AND term_taxonomy_id = %d", $term ) );
     3477                }
    33973478
    3398                 if ( $object_types )
    3399                         $count += (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_relationships, $wpdb->posts WHERE $wpdb->posts.ID = $wpdb->term_relationships.object_id AND post_status = 'publish' AND post_type IN ('" . implode("', '", $object_types ) . "') AND term_taxonomy_id = %d", $term ) );
     3479                if ( $object_types ) {
     3480                        $count += (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_relationships, $wpdb->posts WHERE $wpdb->posts.ID = $wpdb->term_relationships.object_id AND post_status = 'publish' AND post_type IN ('" . implode( "', '", $object_types ) . "') AND term_taxonomy_id = %d", $term ) );
     3481                }
    34003482
    34013483                /** This action is documented in wp-includes/taxonomy.php */
    34023484                do_action( 'edit_term_taxonomy', $term, $taxonomy->name );
     
    38433925function get_term_link( $term, $taxonomy = '' ) {
    38443926        global $wp_rewrite;
    38453927
    3846         if ( !is_object($term) ) {
     3928        if ( ! is_object( $term ) ) {
    38473929                if ( is_int( $term ) ) {
    38483930                        $term = get_term( $term, $taxonomy );
    38493931                } else {
     
    38513933                }
    38523934        }
    38533935
    3854         if ( !is_object($term) )
    3855                 $term = new WP_Error('invalid_term', __('Empty Term'));
     3936        if ( ! is_object( $term ) ) {
     3937                $term = new WP_Error( 'invalid_term', __( 'Empty Term' ) );
     3938        }
    38563939
    3857         if ( is_wp_error( $term ) )
     3940        if ( is_wp_error( $term ) ) {
    38583941                return $term;
     3942        }
    38593943
    38603944        $taxonomy = $term->taxonomy;
    38613945
    3862         $termlink = $wp_rewrite->get_extra_permastruct($taxonomy);
     3946        $termlink = $wp_rewrite->get_extra_permastruct( $taxonomy );
    38633947
    38643948        $slug = $term->slug;
    3865         $t = get_taxonomy($taxonomy);
     3949        $t = get_taxonomy( $taxonomy );
    38663950
    3867         if ( empty($termlink) ) {
    3868                 if ( 'category' == $taxonomy )
     3951        if ( empty( $termlink ) ) {
     3952                if ( 'category' == $taxonomy ) {
    38693953                        $termlink = '?cat=' . $term->term_id;
    3870                 elseif ( $t->query_var )
     3954                } elseif ( $t->query_var ) {
    38713955                        $termlink = "?$t->query_var=$slug";
    3872                 else
    3873                         $termlink = "?taxonomy=$taxonomy&term=$slug";
    3874                 $termlink = home_url($termlink);
     3956                } else { $termlink = "?taxonomy=$taxonomy&term=$slug";
     3957                }
     3958                $termlink = home_url( $termlink );
    38753959        } else {
    38763960                if ( $t->rewrite['hierarchical'] ) {
    38773961                        $hierarchical_slugs = array();
    38783962                        $ancestors = get_ancestors( $term->term_id, $taxonomy, 'taxonomy' );
    3879                         foreach ( (array)$ancestors as $ancestor ) {
    3880                                 $ancestor_term = get_term($ancestor, $taxonomy);
     3963                        foreach ( (array) $ancestors as $ancestor ) {
     3964                                $ancestor_term = get_term( $ancestor, $taxonomy );
    38813965                                $hierarchical_slugs[] = $ancestor_term->slug;
    38823966                        }
    3883                         $hierarchical_slugs = array_reverse($hierarchical_slugs);
     3967                        $hierarchical_slugs = array_reverse( $hierarchical_slugs );
    38843968                        $hierarchical_slugs[] = $slug;
    3885                         $termlink = str_replace("%$taxonomy%", implode('/', $hierarchical_slugs), $termlink);
     3969                        $termlink = str_replace( "%$taxonomy%", implode( '/', $hierarchical_slugs ), $termlink );
    38863970                } else {
    3887                         $termlink = str_replace("%$taxonomy%", $slug, $termlink);
     3971                        $termlink = str_replace( "%$taxonomy%", $slug, $termlink );
    38883972                }
    3889                 $termlink = home_url( user_trailingslashit($termlink, 'category') );
     3973                $termlink = home_url( user_trailingslashit( $termlink, 'category' ) );
    38903974        }
    38913975        // Back Compat filters.
    38923976        if ( 'post_tag' == $taxonomy ) {
     
    40184102                        $links[] = wp_sprintf( $t['term_template'], esc_attr( get_term_link( $term ) ), $term->name );
    40194103                }
    40204104                if ( $links ) {
    4021                         $taxonomies[$taxonomy] = wp_sprintf( $t['template'], $t['label'], $links, $terms );
     4105                        $taxonomies[ $taxonomy ] = wp_sprintf( $t['template'], $t['label'], $links, $terms );
    40224106                }
    40234107        }
    40244108        return $taxonomies;
     
    40354119function get_post_taxonomies( $post = 0 ) {
    40364120        $post = get_post( $post );
    40374121
    4038         return get_object_taxonomies($post);
     4122        return get_object_taxonomies( $post );
    40394123}
    40404124
    40414125/**
     
    40534137 * @return bool|WP_Error WP_Error on input error.
    40544138 */
    40554139function is_object_in_term( $object_id, $taxonomy, $terms = null ) {
    4056         if ( !$object_id = (int) $object_id )
     4140        if ( ! $object_id = (int) $object_id ) {
    40574141                return new WP_Error( 'invalid_object', __( 'Invalid object ID' ) );
     4142        }
    40584143
    40594144        $object_terms = get_object_term_cache( $object_id, $taxonomy );
    40604145        if ( false === $object_terms ) {
     
    40664151                wp_cache_set( $object_id, wp_list_pluck( $object_terms, 'term_id' ), "{$taxonomy}_relationships" );
    40674152        }
    40684153
    4069         if ( is_wp_error( $object_terms ) )
     4154        if ( is_wp_error( $object_terms ) ) {
    40704155                return $object_terms;
    4071         if ( empty( $object_terms ) )
     4156        }
     4157        if ( empty( $object_terms ) ) {
    40724158                return false;
    4073         if ( empty( $terms ) )
    4074                 return ( !empty( $object_terms ) );
     4159        }
     4160        if ( empty( $terms ) ) {
     4161                return ( ! empty( $object_terms ) );
     4162        }
    40754163
    40764164        $terms = (array) $terms;
    40774165
    4078         if ( $ints = array_filter( $terms, 'is_int' ) )
     4166        if ( $ints = array_filter( $terms, 'is_int' ) ) {
    40794167                $strs = array_diff( $terms, $ints );
    4080         else
    4081                 $strs =& $terms;
     4168        } else { $strs =& $terms;
     4169        }
    40824170
    40834171        foreach ( $object_terms as $object_term ) {
    40844172                // If term is an int, check against term_ids only.
     
    40934181                                return true;
    40944182                        }
    40954183
    4096                         if ( in_array( $object_term->name, $strs ) ) return true;
    4097                         if ( in_array( $object_term->slug, $strs ) ) return true;
     4184                        if ( in_array( $object_term->name, $strs ) ) { return true;
     4185                        }
     4186                        if ( in_array( $object_term->slug, $strs ) ) { return true;
     4187                        }
    40984188                }
    40994189        }
    41004190
     
    41514241        }
    41524242
    41534243        if ( 'taxonomy' === $resource_type ) {
    4154                 $term = get_term($object_id, $object_type);
    4155                 while ( ! is_wp_error($term) && ! empty( $term->parent ) && ! in_array( $term->parent, $ancestors ) ) {
     4244                $term = get_term( $object_id, $object_type );
     4245                while ( ! is_wp_error( $term ) && ! empty( $term->parent ) && ! in_array( $term->parent, $ancestors ) ) {
    41564246                        $ancestors[] = (int) $term->parent;
    4157                         $term = get_term($term->parent, $object_type);
     4247                        $term = get_term( $term->parent, $object_type );
    41584248                }
    41594249        } elseif ( 'post_type' === $resource_type ) {
    4160                 $ancestors = get_post_ancestors($object_id);
     4250                $ancestors = get_post_ancestors( $object_id );
    41614251        }
    41624252
    41634253        /**
     
    42074297 */
    42084298function wp_check_term_hierarchy_for_loops( $parent, $term_id, $taxonomy ) {
    42094299        // Nothing fancy here - bail
    4210         if ( !$parent )
     4300        if ( ! $parent ) {
    42114301                return 0;
     4302        }
    42124303
    42134304        // Can't be its own parent.
    4214         if ( $parent == $term_id )
     4305        if ( $parent == $term_id ) {
    42154306                return 0;
     4307        }
    42164308
    42174309        // Now look for larger loops.
    4218         if ( !$loop = wp_find_hierarchy_loop( 'wp_get_term_taxonomy_parent_id', $term_id, $parent, array( $taxonomy ) ) )
     4310        if ( ! $loop = wp_find_hierarchy_loop( 'wp_get_term_taxonomy_parent_id', $term_id, $parent, array( $taxonomy ) ) ) {
    42194311                return $parent; // No loop
     4312        }
    42204313
    42214314        // Setting $parent to the given value causes a loop.
    4222         if ( isset( $loop[$term_id] ) )
     4315        if ( isset( $loop[ $term_id ] ) ) {
    42234316                return 0;
     4317        }
    42244318
    42254319        // There's a loop, but it doesn't contain $term_id. Break the loop.
    4226         foreach ( array_keys( $loop ) as $loop_member )
     4320        foreach ( array_keys( $loop ) as $loop_member ) {
    42274321                wp_update_term( $loop_member, $taxonomy, array( 'parent' => 0 ) );
     4322        }
    42284323
    42294324        return $parent;
    42304325}