Make WordPress Core


Ignore:
Timestamp:
04/09/2020 03:41:04 PM (5 years ago)
Author:
SergeyBiryukov
Message:

Coding Standards: Use strict type check for in_array() and array_search().

This addresses all the remaining WordPress.PHP.StrictInArray.MissingTrueStrict issues in core.

Includes minor code layout fixes for better readability.

Follow-up to [47550].

See #49542.

File:
1 edited

Legend:

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

    r47550 r47557  
    24692469
    24702470        $term_info = term_exists( $term, $taxonomy );
     2471
    24712472        if ( ! $term_info ) {
    24722473            // Skip if a non-existent term ID is passed.
     
    24742475                continue;
    24752476            }
     2477
    24762478            $term_info = wp_insert_term( $term, $taxonomy );
    24772479        }
     2480
    24782481        if ( is_wp_error( $term_info ) ) {
    24792482            return $term_info;
    24802483        }
     2484
    24812485        $term_ids[] = $term_info['term_id'];
    24822486        $tt_id      = $term_info['term_taxonomy_id'];
     
    24982502         */
    24992503        do_action( 'add_term_relationship', $object_id, $tt_id, $taxonomy );
     2504
    25002505        $wpdb->insert(
    25012506            $wpdb->term_relationships,
     
    25172522         */
    25182523        do_action( 'added_term_relationship', $object_id, $tt_id, $taxonomy );
     2524
    25192525        $new_tt_ids[] = $tt_id;
    25202526    }
     
    25402546
    25412547    $t = get_taxonomy( $taxonomy );
     2548
    25422549    if ( ! $append && isset( $t->sort ) && $t->sort ) {
    2543         $values       = array();
    2544         $term_order   = 0;
     2550        $values     = array();
     2551        $term_order = 0;
     2552
    25452553        $final_tt_ids = wp_get_object_terms(
    25462554            $object_id,
     
    25512559            )
    25522560        );
     2561
    25532562        foreach ( $tt_ids as $tt_id ) {
    2554             if ( in_array( $tt_id, $final_tt_ids ) ) {
     2563            if ( in_array( (int) $tt_id, $final_tt_ids, true ) ) {
    25552564                $values[] = $wpdb->prepare( '(%d, %d, %d)', $object_id, $tt_id, ++$term_order );
    25562565            }
    25572566        }
     2567
    25582568        if ( $values ) {
    25592569            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)' ) ) {
     
    25792589     */
    25802590    do_action( 'set_object_terms', $object_id, $terms, $tt_ids, $taxonomy, $append, $old_tt_ids );
     2591
    25812592    return $tt_ids;
    25822593}
     
    36173628    $object_types = esc_sql( $tax_obj->object_type );
    36183629    $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'" );
     3630
    36193631    foreach ( $results as $row ) {
    3620         $id                                   = $term_ids[ $row->term_taxonomy_id ];
     3632        $id = $term_ids[ $row->term_taxonomy_id ];
     3633
    36213634        $term_items[ $id ][ $row->object_id ] = isset( $term_items[ $id ][ $row->object_id ] ) ? ++$term_items[ $id ][ $row->object_id ] : 1;
    36223635    }
     
    36283641        while ( ! empty( $terms_by_id[ $child ] ) && $parent = $terms_by_id[ $child ]->parent ) {
    36293642            $ancestors[] = $child;
     3643
    36303644            if ( ! empty( $term_items[ $term_id ] ) ) {
    36313645                foreach ( $term_items[ $term_id ] as $item_id => $touches ) {
     
    36333647                }
    36343648            }
     3649
    36353650            $child = $parent;
    36363651
    3637             if ( in_array( $parent, $ancestors ) ) {
     3652            if ( in_array( $parent, $ancestors, true ) ) {
    36383653                break;
    36393654            }
     
    45234538    if ( 'taxonomy' === $resource_type ) {
    45244539        $term = get_term( $object_id, $object_type );
    4525         while ( ! is_wp_error( $term ) && ! empty( $term->parent ) && ! in_array( $term->parent, $ancestors ) ) {
     4540        while ( ! is_wp_error( $term ) && ! empty( $term->parent ) && ! in_array( $term->parent, $ancestors, true ) ) {
    45264541            $ancestors[] = (int) $term->parent;
    45274542            $term        = get_term( $term->parent, $object_type );
Note: See TracChangeset for help on using the changeset viewer.