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/class-wp-plugins-list-table.php

    r47167 r47550  
    4040        );
    4141
     42        $status_whitelist = array( 'active', 'inactive', 'recently_activated', 'upgrade', 'mustuse', 'dropins', 'search', 'paused' );
     43
    4244        $status = 'all';
    43         if ( isset( $_REQUEST['plugin_status'] ) && in_array( $_REQUEST['plugin_status'], array( 'active', 'inactive', 'recently_activated', 'upgrade', 'mustuse', 'dropins', 'search', 'paused' ) ) ) {
     45        if ( isset( $_REQUEST['plugin_status'] ) && in_array( $_REQUEST['plugin_status'], $status_whitelist, true ) ) {
    4446            $status = $_REQUEST['plugin_status'];
    4547        }
     
    244246        }
    245247
    246         if ( empty( $plugins[ $status ] ) && ! in_array( $status, array( 'all', 'search' ) ) ) {
     248        if ( empty( $plugins[ $status ] ) && ! in_array( $status, array( 'all', 'search' ), true ) ) {
    247249            $status = 'all';
    248250        }
     
    399401
    400402        return array(
    401             'cb'          => ! in_array( $status, array( 'mustuse', 'dropins' ) ) ? '<input type="checkbox" />' : '',
     403            'cb'          => ! in_array( $status, array( 'mustuse', 'dropins' ), true ) ? '<input type="checkbox" />' : '',
    402404            'name'        => __( 'Plugin' ),
    403405            'description' => __( 'Description' ),
     
    543545        global $status;
    544546
    545         if ( in_array( $status, array( 'mustuse', 'dropins' ) ) ) {
     547        if ( in_array( $status, array( 'mustuse', 'dropins' ), true ) ) {
    546548            return;
    547549        }
     
    557559        global $status;
    558560
    559         if ( ! in_array( $status, array( 'recently_activated', 'mustuse', 'dropins' ) ) ) {
     561        if ( ! in_array( $status, array( 'recently_activated', 'mustuse', 'dropins' ), true ) ) {
    560562            return;
    561563        }
     
    598600        global $status;
    599601
    600         if ( is_multisite() && ! $this->screen->in_admin( 'network' ) && in_array( $status, array( 'mustuse', 'dropins' ) ) ) {
     602        if ( is_multisite() && ! $this->screen->in_admin( 'network' ) && in_array( $status, array( 'mustuse', 'dropins' ), true ) ) {
    601603            return;
    602604        }
     
    832834        $class          = $is_active ? 'active' : 'inactive';
    833835        $checkbox_id    = 'checkbox_' . md5( $plugin_data['Name'] );
    834         if ( $restrict_network_active || $restrict_network_only || in_array( $status, array( 'mustuse', 'dropins' ) ) || ! $compatible_php ) {
     836        if ( $restrict_network_active || $restrict_network_only || in_array( $status, array( 'mustuse', 'dropins' ), true ) || ! $compatible_php ) {
    835837            $checkbox = '';
    836838        } else {
     
    871873        foreach ( $columns as $column_name => $column_display_name ) {
    872874            $extra_classes = '';
    873             if ( in_array( $column_name, $hidden ) ) {
     875            if ( in_array( $column_name, $hidden, true ) ) {
    874876                $extra_classes = ' hidden';
    875877            }
Note: See TracChangeset for help on using the changeset viewer.