Make WordPress Core


Ignore:
Timestamp:
04/05/2020 03:00:44 AM (6 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/post.php

    r47410 r47550  
    135135        // Posts 'submitted for approval' are submitted to $_POST the same as if they were being published.
    136136        // Change status from 'publish' to 'pending' if user lacks permissions to publish or to resave published posts.
    137         if ( isset( $post_data['post_status'] ) && ( in_array( $post_data['post_status'], $published_statuses ) && ! current_user_can( $ptype->cap->publish_posts ) ) ) {
    138                 if ( ! in_array( $previous_status, $published_statuses ) || ! current_user_can( 'edit_post', $post_id ) ) {
     137        if ( isset( $post_data['post_status'] )
     138                && ( in_array( $post_data['post_status'], $published_statuses, true )
     139                && ! current_user_can( $ptype->cap->publish_posts ) )
     140        ) {
     141                if ( ! in_array( $previous_status, $published_statuses, true ) || ! current_user_can( 'edit_post', $post_id ) ) {
    139142                        $post_data['post_status'] = 'pending';
    140143                }
     
    565568                $post_type_object = get_post_type_object( get_post_type( $post_ID ) );
    566569
    567                 if ( ! isset( $post_type_object ) || ( isset( $children ) && in_array( $post_ID, $children ) ) || ! current_user_can( 'edit_post', $post_ID ) ) {
     570                if ( ! isset( $post_type_object )
     571                        || ( isset( $children ) && in_array( $post_ID, $children ) )
     572                        || ! current_user_can( 'edit_post', $post_ID )
     573                ) {
    568574                        $skipped[] = $post_ID;
    569575                        continue;
     
    594600                }
    595601
    596                 if ( isset( $new_cats ) && in_array( 'category', $tax_names ) ) {
     602                if ( isset( $new_cats ) && in_array( 'category', $tax_names, true ) ) {
    597603                        $cats                       = (array) wp_get_post_categories( $post_ID );
    598604                        $post_data['post_category'] = array_unique( array_merge( $cats, $new_cats ) );
     
    10381044
    10391045        // Don't run if no pretty permalinks or post is not published, scheduled, or privately published.
    1040         if ( ! get_option( 'permalink_structure' ) || ! in_array( $post['post_status'], array( 'publish', 'future', 'private' ) ) ) {
     1046        if ( ! get_option( 'permalink_structure' ) || ! in_array( $post['post_status'], array( 'publish', 'future', 'private' ), true ) ) {
    10411047                return;
    10421048        }
     
    11111117        $post_stati = get_post_stati();
    11121118
    1113         if ( isset( $q['post_type'] ) && in_array( $q['post_type'], get_post_types() ) ) {
     1119        if ( isset( $q['post_type'] ) && in_array( $q['post_type'], get_post_types(), true ) ) {
    11141120                $post_type = $q['post_type'];
    11151121        } else {
     
    11211127        $perm             = '';
    11221128
    1123         if ( isset( $q['post_status'] ) && in_array( $q['post_status'], $post_stati ) ) {
     1129        if ( isset( $q['post_status'] ) && in_array( $q['post_status'], $post_stati, true ) ) {
    11241130                $post_status = $q['post_status'];
    11251131                $perm        = 'readable';
     
    11301136        if ( isset( $q['orderby'] ) ) {
    11311137                $orderby = $q['orderby'];
    1132         } elseif ( isset( $q['post_status'] ) && in_array( $q['post_status'], array( 'pending', 'draft' ) ) ) {
     1138        } elseif ( isset( $q['post_status'] ) && in_array( $q['post_status'], array( 'pending', 'draft' ), true ) ) {
    11331139                $orderby = 'modified';
    11341140        }
     
    12951301                        $classes = array( '' );
    12961302                } else {
    1297                         $classes = in_array( $box_id, $closed ) ? array( 'closed' ) : array( '' );
     1303                        $classes = in_array( $box_id, $closed, true ) ? array( 'closed' ) : array( '' );
    12981304                }
    12991305        } else {
     
    13431349
    13441350        // Hack: get_permalink() would return ugly permalink for drafts, so we will fake that our post is published.
    1345         if ( in_array( $post->post_status, array( 'draft', 'pending', 'future' ) ) ) {
     1351        if ( in_array( $post->post_status, array( 'draft', 'pending', 'future' ), true ) ) {
    13461352                $post->post_status = 'publish';
    13471353                $post->post_name   = sanitize_title( $post->post_name ? $post->post_name : $post->post_title, $post->ID );
Note: See TracChangeset for help on using the changeset viewer.