Make WordPress Core


Ignore:
Timestamp:
04/09/2020 03:41:04 PM (4 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-admin/includes/template.php

    r47550 r47557  
    172172
    173173        foreach ( $keys as $k ) {
    174             if ( in_array( $categories[ $k ]->term_id, $args['selected_cats'] ) ) {
     174            if ( in_array( $categories[ $k ]->term_id, $args['selected_cats'], true ) ) {
    175175                $checked_categories[] = $categories[ $k ];
    176176                unset( $categories[ $k ] );
     
    229229
    230230    $popular_ids = array();
     231
    231232    foreach ( (array) $terms as $term ) {
    232233        $popular_ids[] = $term->term_id;
     
    235236        }
    236237        $id      = "popular-$taxonomy-$term->term_id";
    237         $checked = in_array( $term->term_id, $checked_terms ) ? 'checked="checked"' : '';
     238        $checked = in_array( $term->term_id, $checked_terms, true ) ? 'checked="checked"' : '';
    238239        ?>
    239240
     
    292293        /** This filter is documented in wp-includes/category-template.php */
    293294        $name    = esc_html( apply_filters( 'the_category', $category->name, '', '' ) );
    294         $checked = in_array( $cat_id, $checked_categories ) ? ' checked="checked"' : '';
     295        $checked = in_array( $cat_id, $checked_categories, true ) ? ' checked="checked"' : '';
    295296        echo '<li id="link-category-', $cat_id, '"><label for="in-link-category-', $cat_id, '" class="selectit"><input value="', $cat_id, '" type="checkbox" name="link_category[]" id="in-link-category-', $cat_id, '"', $checked, '/> ', $name, '</label></li>';
    296297    }
     
    340341
    341342    $taxonomy_names = get_object_taxonomies( $post->post_type );
     343
    342344    foreach ( $taxonomy_names as $taxonomy_name ) {
    343345        $taxonomy = get_taxonomy( $taxonomy_name );
     
    722724<option value="#NONE#"><?php _e( '&mdash; Select &mdash;' ); ?></option>
    723725        <?php
    724 
    725726        foreach ( $keys as $key ) {
    726727            if ( is_protected_meta( $key, 'post' ) || ! current_user_can( 'add_post_meta', $post->ID, $key ) ) {
     
    835836
    836837    echo "\n\n";
     838
    837839    $map = array(
    838840        'mm' => array( $mm, $cur_mm ),
     
    842844        'mn' => array( $mn, $cur_mn ),
    843845    );
     846
    844847    foreach ( $map as $timeunit => $value ) {
    845848        list( $unit, $curr ) = $value;
     
    869872function page_template_dropdown( $default = '', $post_type = 'page' ) {
    870873    $templates = get_page_templates( null, $post_type );
     874
    871875    ksort( $templates );
     876
    872877    foreach ( array_keys( $templates ) as $template ) {
    873878        $selected = selected( $default, $templates[ $template ], false );
     
    11961201        $filename   = wp_normalize_path( $reflection->getFileName() );
    11971202        $plugin_dir = wp_normalize_path( WP_PLUGIN_DIR );
     1203
    11981204        if ( strpos( $filename, $plugin_dir ) === 0 ) {
    11991205            $filename = str_replace( $plugin_dir, '', $filename );
     
    12011207
    12021208            $plugins = get_plugins();
     1209
    12031210            foreach ( $plugins as $name => $plugin ) {
    12041211                if ( strpos( $name, $filename ) === 0 ) {
     
    12501257    // Pull them out of their previous context/priority and into the one the user chose.
    12511258    $sorted = get_user_option( "meta-box-order_$page" );
     1259
    12521260    if ( ! $already_sorted && $sorted ) {
    12531261        foreach ( $sorted as $box_context => $ids ) {
     
    17811789    if ( $setting ) {
    17821790        $setting_errors = array();
     1791
    17831792        foreach ( (array) $wp_settings_errors as $key => $details ) {
    17841793            if ( $setting == $details['setting'] ) {
     
    17861795            }
    17871796        }
     1797
    17881798        return $setting_errors;
    17891799    }
     
    18341844
    18351845    $output = '';
     1846
    18361847    foreach ( $settings_errors as $key => $details ) {
    18371848        if ( 'updated' === $details['type'] ) {
     
    18561867        $output .= "</div> \n";
    18571868    }
     1869
    18581870    echo $output;
    18591871}
     
    20852097
    20862098        $post_states_string .= ' &mdash; ';
     2099
    20872100        foreach ( $post_states as $state ) {
    20882101            ++$i;
     
    21892202            $header_images = wp_list_pluck( get_uploaded_header_images(), 'attachment_id' );
    21902203
    2191             if ( $meta_header == $stylesheet && in_array( $post->ID, $header_images ) ) {
     2204            if ( $meta_header == $stylesheet && in_array( $post->ID, $header_images, true ) ) {
    21922205                $media_states[] = __( 'Header Image' );
    21932206            }
     
    22432256        $state_count = count( $media_states );
    22442257        $i           = 0;
     2258
    22452259        echo ' &mdash; ';
     2260
    22462261        foreach ( $media_states as $state ) {
    22472262            ++$i;
     
    23702385    $button_shorthand = array( 'primary', 'small', 'large' );
    23712386    $classes          = array( 'button' );
     2387
    23722388    foreach ( $type as $t ) {
    23732389        if ( 'secondary' === $t || 'button-secondary' === $t ) {
    23742390            continue;
    23752391        }
     2392
    23762393        $classes[] = in_array( $t, $button_shorthand, true ) ? 'button-' . $t : $t;
    23772394    }
     2395
    23782396    // Remove empty items, remove duplicate items, and finally build a string.
    23792397    $class = implode( ' ', array_unique( array_filter( $classes ) ) );
Note: See TracChangeset for help on using the changeset viewer.