Make WordPress Core


Ignore:
Timestamp:
04/05/2020 03:00:44 AM (5 years ago)
Author:
SergeyBiryukov
Message:

Coding Standards: Use strict type check for in_array() and array_search() where strings are involved.

This reduces the number of WordPress.PHP.StrictInArray.MissingTrueStrict issues from 486 to 50.

Includes minor code layout fixes for better readability.

See #49542.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/nav-menu.php

    r47219 r47550  
    2626    $object_type     = isset( $request['object_type'] ) ? $request['object_type'] : '';
    2727    $query           = isset( $request['q'] ) ? $request['q'] : '';
    28     $response_format = isset( $request['response-format'] ) && in_array( $request['response-format'], array( 'json', 'markup' ) ) ? $request['response-format'] : 'json';
     28    $response_format = isset( $request['response-format'] ) ? $request['response-format'] : '';
     29
     30    if ( ! $response_format || ! in_array( $response_format, array( 'json', 'markup' ), true ) ) {
     31        $response_format = 'json';
     32    }
    2933
    3034    if ( 'markup' == $response_format ) {
     
    185189        foreach ( array_keys( $wp_meta_boxes['nav-menus'][ $context ] ) as $priority ) {
    186190            foreach ( $wp_meta_boxes['nav-menus'][ $context ][ $priority ] as $box ) {
    187                 if ( in_array( $box['id'], $initial_meta_boxes ) ) {
     191                if ( in_array( $box['id'], $initial_meta_boxes, true ) ) {
    188192                    unset( $box['id'] );
    189193                } else {
     
    337341    $post_type_name = $box['args']->name;
    338342    $post_type      = get_post_type_object( $post_type_name );
     343    $tab_name       = $post_type_name . '-tab';
    339344
    340345    // Paginate browsing for large numbers of post objects.
    341346    $per_page = 50;
    342     $pagenum  = isset( $_REQUEST[ $post_type_name . '-tab' ] ) && isset( $_REQUEST['paged'] ) ? absint( $_REQUEST['paged'] ) : 1;
     347    $pagenum  = isset( $_REQUEST[ $tab_name ] ) && isset( $_REQUEST['paged'] ) ? absint( $_REQUEST['paged'] ) : 1;
    343348    $offset   = 0 < $pagenum ? $per_page * ( $pagenum - 1 ) : 0;
    344349
     
    448453            'base'               => add_query_arg(
    449454                array(
    450                     $post_type_name . '-tab' => 'all',
    451                     'paged'                  => '%#%',
    452                     'item-type'              => 'post_type',
    453                     'item-object'            => $post_type_name,
     455                    $tab_name    => 'all',
     456                    'paged'       => '%#%',
     457                    'item-type'   => 'post_type',
     458                    'item-object' => $post_type_name,
    454459                )
    455460            ),
     
    474479
    475480    $current_tab = 'most-recent';
    476     if ( isset( $_REQUEST[ $post_type_name . '-tab' ] ) && in_array( $_REQUEST[ $post_type_name . '-tab' ], array( 'all', 'search' ) ) ) {
    477         $current_tab = $_REQUEST[ $post_type_name . '-tab' ];
     481
     482    if ( isset( $_REQUEST[ $tab_name ] ) && in_array( $_REQUEST[ $tab_name ], array( 'all', 'search' ), true ) ) {
     483        $current_tab = $_REQUEST[ $tab_name ];
    478484    }
    479485
     
    495501    $search_url      = '';
    496502    if ( $nav_menu_selected_id ) {
    497         $most_recent_url = esc_url( add_query_arg( $post_type_name . '-tab', 'most-recent', remove_query_arg( $removed_args ) ) );
    498         $view_all_url    = esc_url( add_query_arg( $post_type_name . '-tab', 'all', remove_query_arg( $removed_args ) ) );
    499         $search_url      = esc_url( add_query_arg( $post_type_name . '-tab', 'search', remove_query_arg( $removed_args ) ) );
     503        $most_recent_url = esc_url( add_query_arg( $tab_name, 'most-recent', remove_query_arg( $removed_args ) ) );
     504        $view_all_url    = esc_url( add_query_arg( $tab_name, 'all', remove_query_arg( $removed_args ) ) );
     505        $search_url      = esc_url( add_query_arg( $tab_name, 'search', remove_query_arg( $removed_args ) ) );
    500506    }
    501507    ?>
     
    653659        <p class="button-controls wp-clearfix" data-items-type="posttype-<?php echo esc_attr( $post_type_name ); ?>">
    654660            <span class="list-controls hide-if-no-js">
    655                 <input type="checkbox"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?> id="<?php echo esc_attr( $post_type_name . '-tab' ); ?>" class="select-all" />
    656                 <label for="<?php echo esc_attr( $post_type_name . '-tab' ); ?>"><?php _e( 'Select All' ); ?></label>
     661                <input type="checkbox"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?> id="<?php echo esc_attr( $tab_name ); ?>" class="select-all" />
     662                <label for="<?php echo esc_attr( $tab_name ); ?>"><?php _e( 'Select All' ); ?></label>
    657663            </span>
    658664
     
    689695    $taxonomy_name = $box['args']->name;
    690696    $taxonomy      = get_taxonomy( $taxonomy_name );
     697    $tab_name      = $taxonomy_name . '-tab';
    691698
    692699    // Paginate browsing for large numbers of objects.
    693700    $per_page = 50;
    694     $pagenum  = isset( $_REQUEST[ $taxonomy_name . '-tab' ] ) && isset( $_REQUEST['paged'] ) ? absint( $_REQUEST['paged'] ) : 1;
     701    $pagenum  = isset( $_REQUEST[ $tab_name ] ) && isset( $_REQUEST['paged'] ) ? absint( $_REQUEST['paged'] ) : 1;
    695702    $offset   = 0 < $pagenum ? $per_page * ( $pagenum - 1 ) : 0;
    696703
     
    733740            'base'               => add_query_arg(
    734741                array(
    735                     $taxonomy_name . '-tab' => 'all',
    736                     'paged'                 => '%#%',
    737                     'item-type'             => 'taxonomy',
    738                     'item-object'           => $taxonomy_name,
     742                    $tab_name    => 'all',
     743                    'paged'       => '%#%',
     744                    'item-type'   => 'taxonomy',
     745                    'item-object' => $taxonomy_name,
    739746                )
    740747            ),
     
    759766
    760767    $current_tab = 'most-used';
    761     if ( isset( $_REQUEST[ $taxonomy_name . '-tab' ] ) && in_array( $_REQUEST[ $taxonomy_name . '-tab' ], array( 'all', 'most-used', 'search' ) ) ) {
    762         $current_tab = $_REQUEST[ $taxonomy_name . '-tab' ];
     768
     769    if ( isset( $_REQUEST[ $tab_name ] ) && in_array( $_REQUEST[ $tab_name ], array( 'all', 'most-used', 'search' ), true ) ) {
     770        $current_tab = $_REQUEST[ $tab_name ];
    763771    }
    764772
     
    780788    $search_url    = '';
    781789    if ( $nav_menu_selected_id ) {
    782         $most_used_url = esc_url( add_query_arg( $taxonomy_name . '-tab', 'most-used', remove_query_arg( $removed_args ) ) );
    783         $view_all_url  = esc_url( add_query_arg( $taxonomy_name . '-tab', 'all', remove_query_arg( $removed_args ) ) );
    784         $search_url    = esc_url( add_query_arg( $taxonomy_name . '-tab', 'search', remove_query_arg( $removed_args ) ) );
     790        $most_used_url = esc_url( add_query_arg( $tab_name, 'most-used', remove_query_arg( $removed_args ) ) );
     791        $view_all_url  = esc_url( add_query_arg( $tab_name, 'all', remove_query_arg( $removed_args ) ) );
     792        $search_url    = esc_url( add_query_arg( $tab_name, 'search', remove_query_arg( $removed_args ) ) );
    785793    }
    786794    ?>
     
    883891        <p class="button-controls wp-clearfix" data-items-type="taxonomy-<?php echo esc_attr( $taxonomy_name ); ?>">
    884892            <span class="list-controls hide-if-no-js">
    885                 <input type="checkbox"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?> id="<?php echo esc_attr( $taxonomy_name . '-tab' ); ?>" class="select-all" />
    886                 <label for="<?php echo esc_attr( $taxonomy_name . '-tab' ); ?>"><?php _e( 'Select All' ); ?></label>
     893                <input type="checkbox"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?> id="<?php echo esc_attr( $tab_name ); ?>" class="select-all" />
     894                <label for="<?php echo esc_attr( $tab_name ); ?>"><?php _e( 'Select All' ); ?></label>
    887895            </span>
    888896
     
    921929                    ! isset( $_item_object_data['menu-item-type'] ) ||
    922930                    // Or URL is the default.
    923                     in_array( $_item_object_data['menu-item-url'], array( 'https://', 'http://', '' ) ) ||
     931                    in_array( $_item_object_data['menu-item-url'], array( 'https://', 'http://', '' ), true ) ||
    924932                    // Or it's not a custom menu item (but not the custom home page).
    925933                    ! ( 'custom' == $_item_object_data['menu-item-type'] && ! isset( $_item_object_data['menu-item-db-id'] ) ) ||
Note: See TracChangeset for help on using the changeset viewer.