Make WordPress Core

Changeset 47557


Ignore:
Timestamp:
04/09/2020 03:41:04 PM (6 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.

Location:
trunk/src
Files:
28 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-walker-category-checklist.php

    r47550 r47557  
    8484                $args['popular_cats'] = empty( $args['popular_cats'] ) ? array() : $args['popular_cats'];
    8585
    86                 $class = in_array( $category->term_id, $args['popular_cats'] ) ? ' class="popular-category"' : '';
     86                $class = in_array( $category->term_id, $args['popular_cats'], true ) ? ' class="popular-category"' : '';
    8787
    8888                $args['selected_cats'] = empty( $args['selected_cats'] ) ? array() : $args['selected_cats'];
     
    9292                        $inner_class  = 'category';
    9393
    94                         if ( in_array( $category->term_id, $args['selected_cats'] ) ) {
     94                        if ( in_array( $category->term_id, $args['selected_cats'], true ) ) {
    9595                                $inner_class .= ' selected';
    9696                                $aria_checked = 'true';
     
    103103                                esc_html( apply_filters( 'the_category', $category->name, '', '' ) ) . '</div>';
    104104                } else {
     105                        $is_selected = in_array( $category->term_id, $args['selected_cats'], true );
     106                        $is_disabled = ! empty( $args['disabled'] );
     107
    105108                        $output .= "\n<li id='{$taxonomy}-{$category->term_id}'$class>" .
    106109                                '<label class="selectit"><input value="' . $category->term_id . '" type="checkbox" name="' . $name . '[]" id="in-' . $taxonomy . '-' . $category->term_id . '"' .
    107                                 checked( in_array( $category->term_id, $args['selected_cats'] ), true, false ) .
    108                                 disabled( empty( $args['disabled'] ), false, false ) . ' /> ' .
     110                                checked( $is_selected, true, false ) .
     111                                disabled( $is_disabled, true, false ) . ' /> ' .
    109112                                /** This filter is documented in wp-includes/category-template.php */
    110113                                esc_html( apply_filters( 'the_category', $category->name, '', '' ) ) . '</label>';
  • trunk/src/wp-admin/includes/class-wp-filesystem-base.php

    r47122 r47557  
    402402
    403403                for ( $i = 0, $c = count( $attarray ); $i < $c; $i++ ) {
    404                         $key = array_search( $attarray[ $i ], $legal );
     404                        $key = array_search( $attarray[ $i ], $legal, true );
    405405                        if ( $key ) {
    406406                                $realmode .= $legal[ $key ];
  • trunk/src/wp-admin/includes/class-wp-ms-users-list-table.php

    r47550 r47557  
    506506                }
    507507
    508                 if ( current_user_can( 'delete_user', $user->ID ) && ! in_array( $user->user_login, $super_admins ) ) {
     508                if ( current_user_can( 'delete_user', $user->ID ) && ! in_array( $user->user_login, $super_admins, true ) ) {
    509509                        $actions['delete'] = '<a href="' . esc_url( network_admin_url( add_query_arg( '_wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), wp_nonce_url( 'users.php', 'deleteuser' ) . '&amp;action=deleteuser&amp;id=' . $user->ID ) ) ) . '" class="delete">' . __( 'Delete' ) . '</a>';
    510510                }
  • trunk/src/wp-admin/includes/class-wp-terms-list-table.php

    r47550 r47557  
    301301                                        $my_parents[] = $my_parent;
    302302                                        $p            = $my_parent->parent;
    303                                         if ( in_array( $p, $parent_ids ) ) { // Prevent parent loops.
     303                                        if ( in_array( $p, $parent_ids, true ) ) { // Prevent parent loops.
    304304                                                break;
    305305                                        }
  • trunk/src/wp-admin/includes/dashboard.php

    r47550 r47557  
    520520                $user_id = get_current_user_id();
    521521                // Don't create an option if this is a super admin who does not belong to this site.
    522                 if ( in_array( get_current_blog_id(), array_keys( get_blogs_of_user( $user_id ) ) ) ) {
     522                if ( in_array( get_current_blog_id(), array_keys( get_blogs_of_user( $user_id ) ), true ) ) {
    523523                        update_user_option( $user_id, 'dashboard_quick_press_last_post_id', (int) $post->ID ); // Save post_ID.
    524524                }
  • trunk/src/wp-admin/includes/ms.php

    r47550 r47557  
    923923                                                )
    924924                                        );
     925
    925926                                        if ( is_array( $blog_users ) && ! empty( $blog_users ) ) {
    926927                                                $user_site      = "<a href='" . esc_url( get_home_url( $details->userblog_id ) ) . "'>{$details->blogname}</a>";
     
    928929                                                $user_dropdown .= "<select name='blog[$user_id][$key]' id='reassign_user'>";
    929930                                                $user_list      = '';
     931
    930932                                                foreach ( $blog_users as $user ) {
    931                                                         if ( ! in_array( $user->ID, $allusers ) ) {
     933                                                        if ( ! in_array( (int) $user->ID, $allusers, true ) ) {
    932934                                                                $user_list .= "<option value='{$user->ID}'>{$user->user_login}</option>";
    933935                                                        }
    934936                                                }
     937
    935938                                                if ( '' == $user_list ) {
    936939                                                        $user_list = $admin_out;
    937940                                                }
     941
    938942                                                $user_dropdown .= $user_list;
    939943                                                $user_dropdown .= "</select>\n";
  • trunk/src/wp-admin/includes/nav-menu.php

    r47550 r47557  
    11501150                )
    11511151        );
    1152         $messages            = array();
    1153         $menu_items          = array();
     1152
     1153        $messages   = array();
     1154        $menu_items = array();
     1155
    11541156        // Index menu items by DB ID.
    11551157        foreach ( $unsorted_menu_items as $_item ) {
     
    11741176
    11751177        wp_defer_term_counting( true );
     1178
    11761179        // Loop through all the menu items' POST variables.
    11771180        if ( ! empty( $_POST['menu-item-db-id'] ) ) {
     
    12101213        $auto_add        = ! empty( $_POST['auto-add-pages'] );
    12111214        $nav_menu_option = (array) get_option( 'nav_menu_options' );
     1215
    12121216        if ( ! isset( $nav_menu_option['auto_add'] ) ) {
    12131217                $nav_menu_option['auto_add'] = array();
    12141218        }
     1219
    12151220        if ( $auto_add ) {
    1216                 if ( ! in_array( $nav_menu_selected_id, $nav_menu_option['auto_add'] ) ) {
     1221                if ( ! in_array( $nav_menu_selected_id, $nav_menu_option['auto_add'], true ) ) {
    12171222                        $nav_menu_option['auto_add'][] = $nav_menu_selected_id;
    12181223                }
    12191224        } else {
    1220                 $key = array_search( $nav_menu_selected_id, $nav_menu_option['auto_add'] );
     1225                $key = array_search( $nav_menu_selected_id, $nav_menu_option['auto_add'], true );
    12211226                if ( false !== $key ) {
    12221227                        unset( $nav_menu_option['auto_add'][ $key ] );
    12231228                }
    12241229        }
     1230
    12251231        // Remove non-existent/deleted menus.
    12261232        $nav_menu_option['auto_add'] = array_intersect( $nav_menu_option['auto_add'], wp_get_nav_menus( array( 'fields' => 'ids' ) ) );
  • trunk/src/wp-admin/includes/plugin.php

    r47550 r47557  
    21712171                                $whitelist_options[ $page ][] = $key;
    21722172                        } else {
    2173                                 $pos = array_search( $key, $whitelist_options[ $page ] );
     2173                                $pos = array_search( $key, $whitelist_options[ $page ], true );
    21742174                                if ( false === $pos ) {
    21752175                                        $whitelist_options[ $page ][] = $key;
     
    22032203                foreach ( $keys as $key ) {
    22042204                        if ( isset( $whitelist_options[ $page ] ) && is_array( $whitelist_options[ $page ] ) ) {
    2205                                 $pos = array_search( $key, $whitelist_options[ $page ] );
     2205                                $pos = array_search( $key, $whitelist_options[ $page ], true );
    22062206                                if ( false !== $pos ) {
    22072207                                        unset( $whitelist_options[ $page ][ $pos ] );
  • trunk/src/wp-admin/includes/post.php

    r47550 r47557  
    549549
    550550                        foreach ( $pages as $page ) {
    551                                 if ( $page->ID == $parent ) {
    552                                         $parent = $page->post_parent;
     551                                if ( (int) $page->ID === $parent ) {
     552                                        $parent = (int) $page->post_parent;
    553553                                        break;
    554554                                }
     
    569569
    570570                if ( ! isset( $post_type_object )
    571                         || ( isset( $children ) && in_array( $post_ID, $children ) )
     571                        || ( isset( $children ) && in_array( $post_ID, $children, true ) )
    572572                        || ! current_user_can( 'edit_post', $post_ID )
    573573                ) {
  • trunk/src/wp-admin/includes/revision.php

    r47122 r47557  
    315315        $compare_two_mode = is_numeric( $from );
    316316        if ( ! $compare_two_mode ) {
    317                 $found = array_search( $selected_revision_id, array_keys( $revisions ) );
     317                $found = array_search( $selected_revision_id, array_keys( $revisions ), true );
    318318                if ( $found ) {
    319319                        $from = array_keys( array_slice( $revisions, $found - 1, 1, true ) );
  • trunk/src/wp-admin/includes/screen.php

    r47550 r47557  
    129129                                }
    130130
     131                                $is_hidden = in_array( $box['id'], $hidden, true );
     132
    131133                                printf(
    132134                                        '<label for="%1$s-hide"><input class="hide-postbox-tog" name="%1$s-hide" type="checkbox" id="%1$s-hide" value="%1$s" %2$s />%3$s</label>',
    133135                                        esc_attr( $box['id'] ),
    134                                         checked( in_array( $box['id'], $hidden, true ), false, false ),
     136                                        checked( $is_hidden, false, false ),
    135137                                        $widget_title
    136138                                );
  • 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 ) ) );
  • trunk/src/wp-admin/nav-menus.php

    r47198 r47557  
    105105                                                )
    106106                                        ) {
    107 
    108                                                 $parent_db_id = in_array( $menu_item_data['menu_item_parent'], $orders_to_dbids ) ? (int) $menu_item_data['menu_item_parent'] : 0;
     107                                                if ( in_array( (int) $menu_item_data['menu_item_parent'], $orders_to_dbids, true ) ) {
     108                                                        $parent_db_id = (int) $menu_item_data['menu_item_parent'];
     109                                                } else {
     110                                                        $parent_db_id = 0;
     111                                                }
    109112
    110113                                                $parent_object = wp_setup_nav_menu_item( get_post( $parent_db_id ) );
     
    132135                                } elseif (
    133136                                        ! empty( $menu_item_data['menu_item_parent'] ) &&
    134                                         in_array( $menu_item_data['menu_item_parent'], $orders_to_dbids )
     137                                        in_array( (int) $menu_item_data['menu_item_parent'], $orders_to_dbids, true )
    135138                                ) {
    136139                                        $menu_item_data['menu_item_parent'] = (int) get_post_meta( $menu_item_data['menu_item_parent'], '_menu_item_menu_item_parent', true );
     
    169172                                        if (
    170173                                                ! empty( $menu_item_data['menu_item_parent'] ) &&
    171                                                 in_array( $menu_item_data['menu_item_parent'], array_keys( $dbids_to_orders ) ) &&
     174                                                in_array( (int) $menu_item_data['menu_item_parent'], array_keys( $dbids_to_orders ), true ) &&
    172175                                                isset( $orders_to_dbids[ $dbids_to_orders[ $menu_item_id ] - 1 ] ) &&
    173176                                                ( $menu_item_data['menu_item_parent'] == $orders_to_dbids[ $dbids_to_orders[ $menu_item_id ] - 1 ] )
    174177                                        ) {
    175                                                 $parent_db_id  = in_array( $menu_item_data['menu_item_parent'], $orders_to_dbids ) ? (int) $menu_item_data['menu_item_parent'] : 0;
     178                                                if ( in_array( (int) $menu_item_data['menu_item_parent'], $orders_to_dbids, true ) ) {
     179                                                        $parent_db_id = (int) $menu_item_data['menu_item_parent'];
     180                                                } else {
     181                                                        $parent_db_id = 0;
     182                                                }
     183
    176184                                                $parent_object = wp_setup_nav_menu_item( get_post( $parent_db_id ) );
    177185
     
    199207                                                        ) {
    200208                                                                $_possible_parent_id = (int) get_post_meta( $orders_to_dbids[ $dbids_to_orders[ $parent_db_id ] - 1 ], '_menu_item_menu_item_parent', true );
    201                                                                 if ( in_array( $_possible_parent_id, array_keys( $dbids_to_orders ) ) ) {
     209                                                                if ( in_array( $_possible_parent_id, array_keys( $dbids_to_orders ), true ) ) {
    202210                                                                        $menu_item_data['menu_item_parent'] = $_possible_parent_id;
    203211                                                                } else {
     
    226234                                                empty( $menu_item_data['menu_order'] ) ||
    227235                                                empty( $menu_item_data['menu_item_parent'] ) ||
    228                                                 ! in_array( $menu_item_data['menu_item_parent'], array_keys( $dbids_to_orders ) ) ||
     236                                                ! in_array( (int) $menu_item_data['menu_item_parent'], array_keys( $dbids_to_orders ), true ) ||
    229237                                                empty( $orders_to_dbids[ $dbids_to_orders[ $menu_item_id ] - 1 ] ) ||
    230238                                                $orders_to_dbids[ $dbids_to_orders[ $menu_item_id ] - 1 ] != $menu_item_data['menu_item_parent']
     
    801809                                                echo esc_html( $_nav_menu->truncated_name );
    802810
    803                                                 if ( ! empty( $menu_locations ) && in_array( $_nav_menu->term_id, $menu_locations ) ) {
     811                                                if ( ! empty( $menu_locations ) && in_array( $_nav_menu->term_id, $menu_locations, true ) ) {
    804812                                                        $locations_assigned_to_this_menu = array();
    805                                                         foreach ( array_keys( $menu_locations, $_nav_menu->term_id ) as $menu_location_key ) {
     813
     814                                                        foreach ( array_keys( $menu_locations, $_nav_menu->term_id, true ) as $menu_location_key ) {
    806815                                                                if ( isset( $locations[ $menu_location_key ] ) ) {
    807816                                                                        $locations_assigned_to_this_menu[] = $locations[ $menu_location_key ];
     
    816825                                                         * @param int $locations Number of menu locations to list. Default 3.
    817826                                                         */
    818                                                         $assigned_locations = array_slice( $locations_assigned_to_this_menu, 0, absint( apply_filters( 'wp_nav_locations_listed_per_menu', 3 ) ) );
     827                                                        $locations_listed_per_menu = absint( apply_filters( 'wp_nav_locations_listed_per_menu', 3 ) );
     828
     829                                                        $assigned_locations = array_slice( $locations_assigned_to_this_menu, 0, $locations_listed_per_menu );
    819830
    820831                                                        // Adds ellipses following the number of locations defined in $assigned_locations.
     
    957968                                                                if ( ! isset( $auto_add ) ) {
    958969                                                                        $auto_add = get_option( 'nav_menu_options' );
     970
    959971                                                                        if ( ! isset( $auto_add['auto_add'] ) ) {
    960972                                                                                $auto_add = false;
    961                                                                         } elseif ( false !== array_search( $nav_menu_selected_id, $auto_add['auto_add'] ) ) {
     973                                                                        } elseif ( false !== array_search( $nav_menu_selected_id, $auto_add['auto_add'], true ) ) {
    962974                                                                                $auto_add = true;
    963975                                                                        } else {
  • trunk/src/wp-admin/network/site-info.php

    r47198 r47557  
    7373        $existing_details     = get_site( $id );
    7474        $blog_data_checkboxes = array( 'public', 'archived', 'spam', 'mature', 'deleted' );
     75
    7576        foreach ( $blog_data_checkboxes as $c ) {
    76                 if ( ! in_array( $existing_details->$c, array( 0, 1 ) ) ) {
     77                if ( ! in_array( (int) $existing_details->$c, array( 0, 1 ), true ) ) {
    7778                        $blog_data[ $c ] = $existing_details->$c;
    7879                } else {
     
    195196                        <legend class="screen-reader-text"><?php _e( 'Set site attributes' ); ?></legend>
    196197                        <?php foreach ( $attribute_fields as $field_key => $field_label ) : ?>
    197                                 <label><input type="checkbox" name="blog[<?php echo $field_key; ?>]" value="1" <?php checked( (bool) $details->$field_key, true ); ?> <?php disabled( ! in_array( $details->$field_key, array( 0, 1 ) ) ); ?> />
     198                                <label><input type="checkbox" name="blog[<?php echo $field_key; ?>]" value="1" <?php checked( (bool) $details->$field_key, true ); ?> <?php disabled( ! in_array( (int) $details->$field_key, array( 0, 1 ), true ) ); ?> />
    198199                                <?php echo $field_label; ?></label><br/>
    199200                        <?php endforeach; ?>
  • trunk/src/wp-admin/users.php

    r47198 r47557  
    238238                $all_userids = $userids;
    239239
    240                 if ( in_array( $current_user->ID, $userids ) ) {
     240                if ( in_array( $current_user->ID, $userids, true ) ) {
    241241                        $userids = array_diff( $userids, array( $current_user->ID ) );
    242242                }
  • trunk/src/wp-includes/class-http.php

    r47550 r47557  
    10421042                // POST requests should not POST to a redirected location.
    10431043                if ( 'POST' == $args['method'] ) {
    1044                         if ( in_array( $response['response']['code'], array( 302, 303 ) ) ) {
     1044                        if ( in_array( $response['response']['code'], array( 302, 303 ), true ) ) {
    10451045                                $args['method'] = 'GET';
    10461046                        }
  • trunk/src/wp-includes/class-walker-page.php

    r47219 r47557  
    123123                if ( ! empty( $current_page ) ) {
    124124                        $_current_page = get_post( $current_page );
    125                         if ( $_current_page && in_array( $page->ID, $_current_page->ancestors ) ) {
     125
     126                        if ( $_current_page && in_array( $page->ID, $_current_page->ancestors, true ) ) {
    126127                                $css_class[] = 'current_page_ancestor';
    127128                        }
     129
    128130                        if ( $page->ID == $current_page ) {
    129131                                $css_class[] = 'current_page_item';
    130                         } elseif ( $_current_page && $page->ID == $_current_page->post_parent ) {
     132                        } elseif ( $_current_page && $page->ID === $_current_page->post_parent ) {
    131133                                $css_class[] = 'current_page_parent';
    132134                        }
  • trunk/src/wp-includes/class-wp-http-cookie.php

    r45748 r47557  
    193193
    194194                // Port - supports "port-lists" in the format: "80,8000,8080".
    195                 if ( ! empty( $port ) && ! in_array( $url['port'], explode( ',', $port ) ) ) {
     195                if ( ! empty( $port ) && ! in_array( $url['port'], array_map( 'intval', explode( ',', $port ) ), true ) ) {
    196196                        return false;
    197197                }
  • trunk/src/wp-includes/class-wp-http-curl.php

    r47219 r47557  
    239239                                return new WP_Error( 'http_request_failed', $curl_error );
    240240                        }
    241                         if ( in_array( curl_getinfo( $handle, CURLINFO_HTTP_CODE ), array( 301, 302 ) ) ) {
     241                        if ( in_array( curl_getinfo( $handle, CURLINFO_HTTP_CODE ), array( 301, 302 ), true ) ) {
    242242                                curl_close( $handle );
    243243                                return new WP_Error( 'http_request_failed', __( 'Too many redirects.' ) );
     
    287287                                }
    288288                        }
    289                         if ( in_array( curl_getinfo( $handle, CURLINFO_HTTP_CODE ), array( 301, 302 ) ) ) {
     289                        if ( in_array( curl_getinfo( $handle, CURLINFO_HTTP_CODE ), array( 301, 302 ), true ) ) {
    290290                                curl_close( $handle );
    291291                                return new WP_Error( 'http_request_failed', __( 'Too many redirects.' ) );
  • trunk/src/wp-includes/class-wp-query.php

    r47550 r47557  
    31383138                        // Loop over posts and relocate stickies to the front.
    31393139                        for ( $i = 0; $i < $num_posts; $i++ ) {
    3140                                 if ( in_array( $this->posts[ $i ]->ID, $sticky_posts ) ) {
     3140                                if ( in_array( $this->posts[ $i ]->ID, $sticky_posts, true ) ) {
    31413141                                        $sticky_post = $this->posts[ $i ];
    31423142                                        // Remove sticky from current position.
     
    31473147                                        $sticky_offset++;
    31483148                                        // Remove post from sticky posts array.
    3149                                         $offset = array_search( $sticky_post->ID, $sticky_posts );
     3149                                        $offset = array_search( $sticky_post->ID, $sticky_posts, true );
    31503150                                        unset( $sticky_posts[ $offset ] );
    31513151                                }
  • trunk/src/wp-includes/class-wp-theme.php

    r47550 r47557  
    277277                        // Default themes always trump their pretenders.
    278278                        // Properly identify default themes that are inside a directory within wp-content/themes.
    279                         $default_theme_slug = array_search( $this->headers['Name'], self::$default_themes );
     279                        $default_theme_slug = array_search( $this->headers['Name'], self::$default_themes, true );
    280280                        if ( $default_theme_slug ) {
    281281                                if ( basename( $this->stylesheet ) != $default_theme_slug ) {
  • trunk/src/wp-includes/customize/class-wp-customize-nav-menu-setting.php

    r47428 r47557  
    180180
    181181                                        if ( isset( $nav_menu_options['auto_add'] ) && is_array( $nav_menu_options['auto_add'] ) ) {
    182                                                 $value['auto_add'] = in_array( $term->term_id, $nav_menu_options['auto_add'] );
     182                                                $value['auto_add'] = in_array( $term->term_id, $nav_menu_options['auto_add'], true );
    183183                                        }
    184184                                }
     
    189189                        }
    190190                }
     191
    191192                return $value;
    192193        }
     
    603604                }
    604605
    605                 $i = array_search( $menu_id, $nav_menu_options['auto_add'] );
     606                $i = array_search( $menu_id, $nav_menu_options['auto_add'], true );
     607
    606608                if ( $auto_add && false === $i ) {
    607609                        array_push( $nav_menu_options['auto_add'], $this->term_id );
  • trunk/src/wp-includes/general-template.php

    r47550 r47557  
    21812181                ARRAY_N
    21822182        );
     2183
    21832184        if ( $dayswithposts ) {
    21842185                foreach ( (array) $dayswithposts as $daywith ) {
    2185                         $daywithpost[] = $daywith[0];
     2186                        $daywithpost[] = (int) $daywith[0];
    21862187                }
    21872188        }
     
    22102211                }
    22112212
    2212                 if ( in_array( $day, $daywithpost ) ) {
     2213                if ( in_array( $day, $daywithpost, true ) ) {
    22132214                        // Any posts today?
    22142215                        $date_format = gmdate( _x( 'F j, Y', 'daily archives date format' ), strtotime( "{$thisyear}-{$thismonth}-{$day}" ) );
     
    22242225                        $calendar_output .= $day;
    22252226                }
     2227
    22262228                $calendar_output .= '</td>';
    22272229
     
    22352237                $calendar_output .= "\n\t\t" . '<td class="pad" colspan="' . esc_attr( $pad ) . '">&nbsp;</td>';
    22362238        }
     2239
    22372240        $calendar_output .= "\n\t</tr>\n\t</tbody>";
    22382241
  • trunk/src/wp-includes/link-template.php

    r47550 r47557  
    36883688
    36893689        $blogs = get_blogs_of_user( $user_id );
     3690
    36903691        if ( is_multisite() && ! user_can( $user_id, 'manage_network' ) && empty( $blogs ) ) {
    36913692                $url = user_admin_url( $path, $scheme );
     
    36943695        } else {
    36953696                $current_blog = get_current_blog_id();
    3696                 if ( $current_blog && ( user_can( $user_id, 'manage_network' ) || in_array( $current_blog, array_keys( $blogs ) ) ) ) {
     3697
     3698                if ( $current_blog && ( user_can( $user_id, 'manage_network' ) || in_array( $current_blog, array_keys( $blogs ), true ) ) ) {
    36973699                        $url = admin_url( $path, $scheme );
    36983700                } else {
  • trunk/src/wp-includes/nav-menu-template.php

    r47550 r47557  
    393393
    394394                // If the menu item corresponds to a taxonomy term for the currently queried non-hierarchical post object.
    395                 if ( $wp_query->is_singular && 'taxonomy' == $menu_item->type && in_array( $menu_item->object_id, $possible_object_parents ) ) {
     395                if ( $wp_query->is_singular && 'taxonomy' == $menu_item->type
     396                        && in_array( (int) $menu_item->object_id, $possible_object_parents, true )
     397                ) {
    396398                        $active_parent_object_ids[] = (int) $menu_item->object_id;
    397399                        $active_parent_item_ids[]   = (int) $menu_item->db_id;
     
    405407                                || ( 'post_type' == $menu_item->type && $wp_query->is_singular )
    406408                                || ( 'taxonomy' == $menu_item->type
    407                                         && ( $wp_query->is_category || $wp_query->is_tag || $wp_query->is_tax ) && $queried_object->taxonomy == $menu_item->object )
     409                                        && ( $wp_query->is_category || $wp_query->is_tag || $wp_query->is_tax )
     410                                        && $queried_object->taxonomy == $menu_item->object )
    408411                        )
    409412                ) {
     
    526529                                        && ! empty( $queried_object->post_type )
    527530                                        && is_post_type_hierarchical( $queried_object->post_type )
    528                                         && in_array( $parent_item->object_id, $queried_object->ancestors )
     531                                        && in_array( (int) $parent_item->object_id, $queried_object->ancestors, true )
    529532                                        && $parent_item->object != $queried_object->ID
    530533                                ) ||
     
    534537                                        'taxonomy' == $parent_item->type
    535538                                        && isset( $possible_taxonomy_ancestors[ $parent_item->object ] )
    536                                         && in_array( $parent_item->object_id, $possible_taxonomy_ancestors[ $parent_item->object ] )
     539                                        && in_array( (int) $parent_item->object_id, $possible_taxonomy_ancestors[ $parent_item->object ], true )
    537540                                        && (
    538541                                                ! isset( $queried_object->term_id ) ||
  • trunk/src/wp-includes/post.php

    r47550 r47557  
    22852285        $stickies = get_option( 'sticky_posts' );
    22862286
    2287         $is_sticky = is_array( $stickies ) && in_array( $post_id, $stickies );
     2287        if ( is_array( $stickies ) ) {
     2288                $stickies  = array_map( 'intval', $stickies );
     2289                $is_sticky = in_array( $post_id, $stickies, true );
     2290        } else {
     2291                $is_sticky = false;
     2292        }
    22882293
    22892294        /**
     
    25122517 */
    25132518function stick_post( $post_id ) {
     2519        $post_id  = (int) $post_id;
    25142520        $stickies = get_option( 'sticky_posts' );
    25152521
    25162522        if ( ! is_array( $stickies ) ) {
    2517                 $stickies = array( $post_id );
    2518         }
    2519 
    2520         if ( ! in_array( $post_id, $stickies ) ) {
     2523                $stickies = array();
     2524        }
     2525
     2526        $stickies = array_map( 'intval', $stickies );
     2527
     2528        if ( ! in_array( $post_id, $stickies, true ) ) {
    25212529                $stickies[] = $post_id;
    25222530        }
     
    25462554 */
    25472555function unstick_post( $post_id ) {
     2556        $post_id  = (int) $post_id;
    25482557        $stickies = get_option( 'sticky_posts' );
    25492558
     
    25522561        }
    25532562
    2554         if ( ! in_array( $post_id, $stickies ) ) {
     2563        $stickies = array_map( 'intval', $stickies );
     2564
     2565        if ( ! in_array( $post_id, $stickies, true ) ) {
    25552566                return;
    25562567        }
    25572568
    2558         $offset = array_search( $post_id, $stickies );
     2569        $offset = array_search( $post_id, $stickies, true );
    25592570        if ( false === $offset ) {
    25602571                return;
     
    28422853                $mimes = array_map( 'trim', explode( ',', $type ) );
    28432854                foreach ( $mimes as $mime ) {
    2844                         $regex                 = str_replace( '__wildcard__', $wild, preg_quote( str_replace( '*', '__wildcard__', $mime ) ) );
     2855                        $regex = str_replace( '__wildcard__', $wild, preg_quote( str_replace( '*', '__wildcard__', $mime ) ) );
     2856
    28452857                        $patternses[][ $type ] = "^$regex$";
     2858
    28462859                        if ( false === strpos( $mime, '/' ) ) {
    28472860                                $patternses[][ $type ] = "^$regex/";
     
    28552868                foreach ( $patterns as $type => $pattern ) {
    28562869                        foreach ( (array) $real_mime_types as $real ) {
    2857                                 if ( preg_match( "#$pattern#", $real ) && ( empty( $matches[ $type ] ) || false === array_search( $real, $matches[ $type ] ) ) ) {
     2870                                if ( preg_match( "#$pattern#", $real )
     2871                                        && ( empty( $matches[ $type ] ) || false === array_search( $real, $matches[ $type ], true ) )
     2872                                ) {
    28582873                                        $matches[ $type ][] = $real;
    28592874                                }
     
    28612876                }
    28622877        }
     2878
    28632879        return $matches;
    28642880}
     
    29152931                }
    29162932        }
     2933
    29172934        if ( ! empty( $wheres ) ) {
    29182935                $where = ' AND (' . join( ' OR ', $wheres ) . ') ';
    29192936        }
     2937
    29202938        return $where;
    29212939}
     
    44374455                $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post_type, $post_ID ) );
    44384456
     4457                $post = get_post( $post_ID );
     4458
    44394459                // Prevent new post slugs that could result in URLs that conflict with date archives.
    4440                 $post                        = get_post( $post_ID );
    44414460                $conflicts_with_date_archive = false;
    44424461                if ( 'post' === $post_type && ( ! $post || $post->post_name !== $slug ) && preg_match( '/^[0-9]+$/', $slug ) ) {
     
    44454464                        if ( $slug_num ) {
    44464465                                $permastructs   = array_values( array_filter( explode( '/', get_option( 'permalink_structure' ) ) ) );
    4447                                 $postname_index = array_search( '%postname%', $permastructs );
     4466                                $postname_index = array_search( '%postname%', $permastructs, true );
    44484467
    44494468                                /*
     
    55015520                $num_pages = count( $pages );
    55025521                for ( $i = 0; $i < $num_pages; $i++ ) {
    5503                         if ( in_array( $pages[ $i ]->ID, $exclude ) ) {
     5522                        if ( in_array( $pages[ $i ]->ID, $exclude, true ) ) {
    55045523                                unset( $pages[ $i ] );
    55055524                        }
     
    58125831function wp_get_attachment_metadata( $attachment_id = 0, $unfiltered = false ) {
    58135832        $attachment_id = (int) $attachment_id;
    5814         $post          = get_post( $attachment_id );
     5833
     5834        $post = get_post( $attachment_id );
    58155835        if ( ! $post ) {
    58165836                return false;
     
    58465866function wp_update_attachment_metadata( $attachment_id, $data ) {
    58475867        $attachment_id = (int) $attachment_id;
    5848         $post          = get_post( $attachment_id );
     5868
     5869        $post = get_post( $attachment_id );
    58495870        if ( ! $post ) {
    58505871                return false;
     
    58795900function wp_get_attachment_url( $attachment_id = 0 ) {
    58805901        $attachment_id = (int) $attachment_id;
    5881         $post          = get_post( $attachment_id );
     5902
     5903        $post = get_post( $attachment_id );
    58825904        if ( ! $post ) {
    58835905                return false;
  • trunk/src/wp-includes/rewrite.php

    r47550 r47557  
    597597                        $query = array();
    598598                        foreach ( (array) $query_vars as $key => $value ) {
    599                                 if ( in_array( $key, $wp->public_query_vars, true ) ) {
     599                                if ( in_array( (string) $key, $wp->public_query_vars, true ) ) {
    600600                                        $query[ $key ] = $value;
    601601                                        if ( isset( $post_type_query_vars[ $key ] ) ) {
  • 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.