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/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' ) ) );
Note: See TracChangeset for help on using the changeset viewer.