Make WordPress Core


Ignore:
Timestamp:
08/01/2019 01:44:04 PM (7 years ago)
Author:
SergeyBiryukov
Message:

Coding Standards: Use strict comparison in wp-includes/taxonomy.php.

Props andizer, SergeyBiryukov.
Fixes #47573.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/taxonomy.php

    r45702 r45710  
    194194        global $wp_taxonomies;
    195195
    196         $field = ( 'names' == $output ) ? 'name' : false;
     196        $field = ( 'names' === $output ) ? 'name' : false;
    197197
    198198        return wp_filter_object_list( $wp_taxonomies, $args, $operator, $field );
     
    224224
    225225        if ( is_object( $object ) ) {
    226                 if ( $object->post_type == 'attachment' ) {
     226                if ( $object->post_type === 'attachment' ) {
    227227                        return get_attachment_taxonomies( $object, $output );
    228228                }
     
    235235        foreach ( (array) $wp_taxonomies as $tax_name => $tax_obj ) {
    236236                if ( array_intersect( $object, (array) $tax_obj->object_type ) ) {
    237                         if ( 'names' == $output ) {
     237                        if ( 'names' === $output ) {
    238238                                $taxonomies[] = $tax_name;
    239239                        } else {
     
    726726        $args     = wp_parse_args( $args, $defaults );
    727727
    728         $order = ( 'desc' == strtolower( $args['order'] ) ) ? 'DESC' : 'ASC';
     728        $order = ( 'desc' === strtolower( $args['order'] ) ) ? 'DESC' : 'ASC';
    729729
    730730        $term_ids = array_map( 'intval', $term_ids );
     
    877877        $_term->filter( $filter );
    878878
    879         if ( $output == ARRAY_A ) {
     879        if ( $output === ARRAY_A ) {
    880880                return $_term->to_array();
    881         } elseif ( $output == ARRAY_N ) {
     881        } elseif ( $output === ARRAY_N ) {
    882882                return array_values( $_term->to_array() );
    883883        }
     
    10151015
    10161016        foreach ( (array) $terms[ $term_id ] as $child ) {
    1017                 if ( $term_id == $child ) {
     1017                if ( $term_id === $child ) {
    10181018                        continue;
    10191019                }
     
    13721372
    13731373        if ( is_int( $term ) ) {
    1374                 if ( 0 == $term ) {
     1374                if ( 0 === $term ) {
    13751375                        return 0;
    13761376                }
     
    14461446                return false;
    14471447        }
    1448         if ( $term2->parent == $term1->term_id ) {
     1448        if ( $term2->parent === $term1->term_id ) {
    14491449                return true;
    14501450        }
     
    15301530        }
    15311531
    1532         if ( 'raw' == $context ) {
     1532        $context = strtolower( $context );
     1533
     1534        if ( 'raw' === $context ) {
    15331535                return $value;
    15341536        }
    15351537
    1536         if ( 'edit' == $context ) {
     1538        if ( 'edit' === $context ) {
    15371539
    15381540                /**
     
    15621564                $value = apply_filters( "edit_{$taxonomy}_{$field}", $value, $term_id );
    15631565
    1564                 if ( 'description' == $field ) {
     1566                if ( 'description' === $field ) {
    15651567                        $value = esc_html( $value ); // textarea_escaped
    15661568                } else {
    15671569                        $value = esc_attr( $value );
    15681570                }
    1569         } elseif ( 'db' == $context ) {
     1571        } elseif ( 'db' === $context ) {
    15701572
    15711573                /**
     
    15941596
    15951597                // Back compat filters
    1596                 if ( 'slug' == $field ) {
     1598                if ( 'slug' === $field ) {
    15971599                        /**
    15981600                         * Filters the category nicename before it is sanitized.
     
    16061608                        $value = apply_filters( 'pre_category_nicename', $value );
    16071609                }
    1608         } elseif ( 'rss' == $context ) {
     1610        } elseif ( 'rss' === $context ) {
    16091611
    16101612                /**
     
    16631665        }
    16641666
    1665         if ( 'attribute' == $context ) {
     1667        if ( 'attribute' === $context ) {
    16661668                $value = esc_attr( $value );
    1667         } elseif ( 'js' == $context ) {
     1669        } elseif ( 'js' === $context ) {
    16681670                $value = esc_js( $value );
    16691671        }
     
    17681770        $defaults = array();
    17691771
    1770         if ( 'category' == $taxonomy ) {
     1772        if ( 'category' === $taxonomy ) {
    17711773                $defaults['default'] = get_option( 'default_category' );
    1772                 if ( $defaults['default'] == $term ) {
     1774                if ( $defaults['default'] === $term ) {
    17731775                        return 0; // Don't delete the default category
    17741776                }
     
    18481850                        )
    18491851                );
    1850                 if ( 1 == count( $terms ) && isset( $default ) ) {
     1852                if ( 1 === count( $terms ) && isset( $default ) ) {
    18511853                        $terms = array( $default );
    18521854                } else {
     
    21242126                return $term;
    21252127        }
    2126         if ( is_int( $term ) && 0 == $term ) {
     2128        if ( is_int( $term ) && 0 === $term ) {
    21272129                return new WP_Error( 'invalid_term_id', __( 'Invalid term ID.' ) );
    21282130        }
    2129         if ( '' == trim( $term ) ) {
     2131        if ( '' === trim( $term ) ) {
    21302132                return new WP_Error( 'empty_term_name', __( 'A name is required for this term.' ) );
    21312133        }
     
    24512453
    24522454        foreach ( (array) $terms as $term ) {
    2453                 if ( ! strlen( trim( $term ) ) ) {
     2455                if ( '' === trim( $term ) ) {
    24542456                        continue;
    24552457                }
     
    26112613
    26122614        foreach ( (array) $terms as $term ) {
    2613                 if ( ! strlen( trim( $term ) ) ) {
     2615                if ( '' === trim( $term ) ) {
    26142616                        continue;
    26152617                }
     
    28472849        $parsed_args['description'] = $description;
    28482850
    2849         if ( '' == trim( $name ) ) {
     2851        if ( '' === trim( $name ) ) {
    28502852                return new WP_Error( 'empty_term_name', __( 'A name is required for this term.' ) );
    28512853        }
     
    29032905         * @param array  $args        An array of update arguments for the given term.
    29042906         */
    2905         $parent = apply_filters( 'wp_update_term_parent', $args['parent'], $term_id, $taxonomy, $parsed_args, $args );
     2907        $parent = (int) apply_filters( 'wp_update_term_parent', $args['parent'], $term_id, $taxonomy, $parsed_args, $args );
    29062908
    29072909        // Check for duplicate slug
    29082910        $duplicate = get_term_by( 'slug', $slug, $taxonomy );
    2909         if ( $duplicate && $duplicate->term_id != $term_id ) {
     2911        if ( $duplicate && $duplicate->term_id !== $term_id ) {
    29102912                // If an empty slug was passed or the parent changed, reset the slug to something unique.
    29112913                // Otherwise, bail.
    2912                 if ( $empty_slug || ( $parent != $term['parent'] ) ) {
     2914                if ( $empty_slug || ( $parent !== (int) $term['parent'] ) ) {
    29132915                        $slug = wp_unique_term_slug( $slug, (object) $args );
    29142916                } else {
     
    35123514        }
    35133515
     3516        $term_id      = (int) $term_id;
    35143517        $term_list    = array();
    35153518        $has_children = _get_term_hierarchy( $taxonomy );
    35163519
    3517         if ( ( 0 != $term_id ) && ! isset( $has_children[ $term_id ] ) ) {
     3520        if ( $term_id && ! isset( $has_children[ $term_id ] ) ) {
    35183521                return $empty_array;
    35193522        }
     
    35393542                }
    35403543
    3541                 if ( $term->parent == $term_id ) {
     3544                if ( $term->parent === $term_id ) {
    35423545                        if ( $use_id ) {
    35433546                                $term_list[] = $term->term_id;
     
    37863789
    37873790        // If there are no shared term_taxonomy rows, there's nothing to do here.
    3788         $shared_tt_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_taxonomy tt WHERE tt.term_id = %d AND tt.term_taxonomy_id != %d", $term_id, $term_taxonomy_id ) );
     3791        $shared_tt_count = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_taxonomy tt WHERE tt.term_id = %d AND tt.term_taxonomy_id != %d", $term_id, $term_taxonomy_id ) );
    37893792
    37903793        if ( ! $shared_tt_count ) {
     
    37963799         * If there's a mismatch, it may mean that the term is already split. Return the actual term_id from the db.
    37973800         */
    3798         $check_term_id = $wpdb->get_var( $wpdb->prepare( "SELECT term_id FROM $wpdb->term_taxonomy WHERE term_taxonomy_id = %d", $term_taxonomy_id ) );
    3799         if ( $check_term_id != $term_id ) {
     3801        $check_term_id = (int) $wpdb->get_var( $wpdb->prepare( "SELECT term_id FROM $wpdb->term_taxonomy WHERE term_taxonomy_id = %d", $term_taxonomy_id ) );
     3802        if ( $check_term_id !== $term_id ) {
    38003803                return $check_term_id;
    38013804        }
     
    40204023 */
    40214024function _wp_check_split_default_terms( $term_id, $new_term_id, $term_taxonomy_id, $taxonomy ) {
    4022         if ( 'category' != $taxonomy ) {
     4025        if ( 'category' !== $taxonomy ) {
    40234026                return;
    40244027        }
    40254028
    40264029        foreach ( array( 'default_category', 'default_link_category', 'default_email_category' ) as $option ) {
    4027                 if ( $term_id == get_option( $option, -1 ) ) {
     4030                if ( $term_id === (int) get_option( $option, -1 ) ) {
    40284031                        update_option( $option, $new_term_id );
    40294032                }
     
    40864089        $locations = get_nav_menu_locations();
    40874090        foreach ( $locations as $location => $menu_id ) {
    4088                 if ( $term_id == $menu_id ) {
     4091                if ( $term_id === $menu_id ) {
    40894092                        $locations[ $location ] = $new_term_id;
    40904093                }
     
    42064209
    42074210        if ( empty( $termlink ) ) {
    4208                 if ( 'category' == $taxonomy ) {
     4211                if ( 'category' === $taxonomy ) {
    42094212                        $termlink = '?cat=' . $term->term_id;
    42104213                } elseif ( $t->query_var ) {
     
    42314234        }
    42324235        // Back Compat filters.
    4233         if ( 'post_tag' == $taxonomy ) {
     4236        if ( 'post_tag' === $taxonomy ) {
    42344237
    42354238                /**
     
    42434246                 */
    42444247                $termlink = apply_filters( 'tag_link', $termlink, $term->term_id );
    4245         } elseif ( 'category' == $taxonomy ) {
     4248        } elseif ( 'category' === $taxonomy ) {
    42464249
    42474250                /**
     
    45684571
    45694572        // Can't be its own parent.
    4570         if ( $parent == $term_id ) {
     4573        if ( $parent === $term_id ) {
    45714574                return 0;
    45724575        }
Note: See TracChangeset for help on using the changeset viewer.