WordPress.org

Make WordPress Core


Ignore:
Timestamp:
05/16/2020 06:40:52 PM (11 months ago)
Author:
SergeyBiryukov
Message:

Coding Standards: Use strict comparison where static strings are involved.

This reduces the number of WordPress.PHP.StrictComparisons.LooseComparison issues in half, from 1897 to 890.

Includes minor code layout fixes for better readability.

See #49542.

File:
1 edited

Legend:

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

    r47557 r47808  
    3131
    3232    if ( $update && ! current_user_can( 'edit_post', $post_data['ID'] ) ) {
    33         if ( 'page' == $post_data['post_type'] ) {
     33        if ( 'page' === $post_data['post_type'] ) {
    3434            return new WP_Error( 'edit_others_pages', __( 'Sorry, you are not allowed to edit pages as this user.' ) );
    3535        } else {
     
    3737        }
    3838    } elseif ( ! $update && ! current_user_can( $ptype->cap->create_posts ) ) {
    39         if ( 'page' == $post_data['post_type'] ) {
     39        if ( 'page' === $post_data['post_type'] ) {
    4040            return new WP_Error( 'edit_others_pages', __( 'Sorry, you are not allowed to create pages as this user.' ) );
    4141        } else {
     
    7676
    7777        if ( $update ) {
    78             if ( 'page' == $post_data['post_type'] ) {
     78            if ( 'page' === $post_data['post_type'] ) {
    7979                return new WP_Error( 'edit_others_pages', __( 'Sorry, you are not allowed to edit pages as this user.' ) );
    8080            } else {
     
    8282            }
    8383        } else {
    84             if ( 'page' == $post_data['post_type'] ) {
     84            if ( 'page' === $post_data['post_type'] ) {
    8585                return new WP_Error( 'edit_others_pages', __( 'Sorry, you are not allowed to create pages as this user.' ) );
    8686            } else {
     
    104104
    105105    // What to do based on which button they pressed.
    106     if ( isset( $post_data['saveasdraft'] ) && '' != $post_data['saveasdraft'] ) {
     106    if ( isset( $post_data['saveasdraft'] ) && '' !== $post_data['saveasdraft'] ) {
    107107        $post_data['post_status'] = 'draft';
    108108    }
    109     if ( isset( $post_data['saveasprivate'] ) && '' != $post_data['saveasprivate'] ) {
     109    if ( isset( $post_data['saveasprivate'] ) && '' !== $post_data['saveasprivate'] ) {
    110110        $post_data['post_status'] = 'private';
    111111    }
    112     if ( isset( $post_data['publish'] ) && ( '' != $post_data['publish'] ) && ( ! isset( $post_data['post_status'] ) || 'private' !== $post_data['post_status'] ) ) {
     112    if ( isset( $post_data['publish'] ) && ( '' !== $post_data['publish'] )
     113        && ( ! isset( $post_data['post_status'] ) || 'private' !== $post_data['post_status'] )
     114    ) {
    113115        $post_data['post_status'] = 'publish';
    114116    }
    115     if ( isset( $post_data['advanced'] ) && '' != $post_data['advanced'] ) {
     117    if ( isset( $post_data['advanced'] ) && '' !== $post_data['advanced'] ) {
    116118        $post_data['post_status'] = 'draft';
    117119    }
    118     if ( isset( $post_data['pending'] ) && '' != $post_data['pending'] ) {
     120    if ( isset( $post_data['pending'] ) && '' !== $post_data['pending'] ) {
    119121        $post_data['post_status'] = 'pending';
    120122    }
     
    127129    $previous_status = $post_id ? get_post_field( 'post_status', $post_id ) : false;
    128130
    129     if ( isset( $post_data['post_status'] ) && 'private' == $post_data['post_status'] && ! current_user_can( $ptype->cap->publish_posts ) ) {
     131    if ( isset( $post_data['post_status'] ) && 'private' === $post_data['post_status'] && ! current_user_can( $ptype->cap->publish_posts ) ) {
    130132        $post_data['post_status'] = $previous_status ? $previous_status : 'pending';
    131133    }
     
    248250        $post_data['post_status'] = sanitize_key( $post_data['post_status'] );
    249251
    250         if ( 'inherit' == $post_data['post_status'] ) {
     252        if ( 'inherit' === $post_data['post_status'] ) {
    251253            unset( $post_data['post_status'] );
    252254        }
     
    255257    $ptype = get_post_type_object( $post_data['post_type'] );
    256258    if ( ! current_user_can( 'edit_post', $post_ID ) ) {
    257         if ( 'page' == $post_data['post_type'] ) {
     259        if ( 'page' === $post_data['post_type'] ) {
    258260            wp_die( __( 'Sorry, you are not allowed to edit this page.' ) );
    259261        } else {
     
    377379
    378380    // Attachment stuff.
    379     if ( 'attachment' == $post_data['post_type'] ) {
     381    if ( 'attachment' === $post_data['post_type'] ) {
    380382        if ( isset( $post_data['_wp_attachment_image_alt'] ) ) {
    381383            $image_alt = wp_unslash( $post_data['_wp_attachment_image_alt'] );
     
    468470
    469471    if ( ! current_user_can( $ptype->cap->edit_posts ) ) {
    470         if ( 'page' == $ptype->name ) {
     472        if ( 'page' === $ptype->name ) {
    471473            wp_die( __( 'Sorry, you are not allowed to edit pages.' ) );
    472474        } else {
     
    486488        $post_data['post_status'] = sanitize_key( $post_data['post_status'] );
    487489
    488         if ( 'inherit' == $post_data['post_status'] ) {
     490        if ( 'inherit' === $post_data['post_status'] ) {
    489491            unset( $post_data['post_status'] );
    490492        }
     
    509511
    510512    foreach ( $reset as $field ) {
    511         if ( isset( $post_data[ $field ] ) && ( '' == $post_data[ $field ] || -1 == $post_data[ $field ] ) ) {
     513        if ( isset( $post_data[ $field ] ) && ( '' === $post_data[ $field ] || -1 == $post_data[ $field ] ) ) {
    512514            unset( $post_data[ $field ] );
    513515        }
     
    633635
    634636        if ( isset( $post_data['sticky'] ) && current_user_can( $ptype->cap->edit_others_posts ) ) {
    635             if ( 'sticky' == $post_data['sticky'] ) {
     637            if ( 'sticky' === $post_data['sticky'] ) {
    636638                stick_post( $post_ID );
    637639            } else {
     
    814816
    815817    if ( ! current_user_can( $ptype->cap->edit_posts ) ) {
    816         if ( 'page' == $ptype->name ) {
     818        if ( 'page' === $ptype->name ) {
    817819            return new WP_Error( 'edit_pages', __( 'Sorry, you are not allowed to create pages on this site.' ) );
    818820        } else {
     
    913915    }
    914916
    915     if ( ( ( '#NONE#' != $metakeyselect ) && ! empty( $metakeyselect ) ) || ! empty( $metakeyinput ) ) {
     917    if ( ( ( '#NONE#' !== $metakeyselect ) && ! empty( $metakeyselect ) ) || ! empty( $metakeyinput ) ) {
    916918        /*
    917919         * We have a key/value pair. If both the select and the input
    918920         * for the key have data, the input takes precedence.
    919921         */
    920         if ( '#NONE#' != $metakeyselect ) {
     922        if ( '#NONE#' !== $metakeyselect ) {
    921923            $metakey = $metakeyselect;
    922924        }
     
    11441146    if ( isset( $q['order'] ) ) {
    11451147        $order = $q['order'];
    1146     } elseif ( isset( $q['post_status'] ) && 'pending' == $q['post_status'] ) {
     1148    } elseif ( isset( $q['post_status'] ) && 'pending' === $q['post_status'] ) {
    11471149        $order = 'ASC';
    11481150    }
     
    12211223    }
    12221224
    1223     $q['post_status'] = isset( $q['status'] ) && 'trash' == $q['status'] ? 'trash' : $states;
    1224     $q['post_status'] = isset( $q['attachment-filter'] ) && 'trash' == $q['attachment-filter'] ? 'trash' : $states;
     1225    $q['post_status'] = isset( $q['status'] ) && 'trash' === $q['status'] ? 'trash' : $states;
     1226    $q['post_status'] = isset( $q['attachment-filter'] ) && 'trash' === $q['attachment-filter'] ? 'trash' : $states;
    12251227
    12261228    $media_per_page = (int) get_user_option( 'upload_per_page' );
     
    12441246
    12451247    foreach ( array_keys( $post_mime_types ) as $type ) {
    1246         if ( isset( $q['attachment-filter'] ) && "post_mime_type:$type" == $q['attachment-filter'] ) {
     1248        if ( isset( $q['attachment-filter'] ) && "post_mime_type:$type" === $q['attachment-filter'] ) {
    12471249            $q['post_mime_type'] = $type;
    12481250            break;
     
    12501252    }
    12511253
    1252     if ( isset( $q['detached'] ) || ( isset( $q['attachment-filter'] ) && 'detached' == $q['attachment-filter'] ) ) {
     1254    if ( isset( $q['detached'] ) || ( isset( $q['attachment-filter'] ) && 'detached' === $q['attachment-filter'] ) ) {
    12531255        $q['post_parent'] = 0;
    12541256    }
    12551257
    1256     if ( isset( $q['mine'] ) || ( isset( $q['attachment-filter'] ) && 'mine' == $q['attachment-filter'] ) ) {
     1258    if ( isset( $q['mine'] ) || ( isset( $q['attachment-filter'] ) && 'mine' === $q['attachment-filter'] ) ) {
    12571259        $q['author'] = get_current_user_id();
    12581260    }
     
    14591461
    14601462        // Encourage a pretty permalink setting.
    1461         if ( '' == get_option( 'permalink_structure' ) && current_user_can( 'manage_options' ) && ! ( 'page' == get_option( 'show_on_front' ) && get_option( 'page_on_front' ) == $id ) ) {
     1463        if ( ! get_option( 'permalink_structure' ) && current_user_can( 'manage_options' )
     1464            && ! ( 'page' === get_option( 'show_on_front' ) && get_option( 'page_on_front' ) == $id )
     1465        ) {
    14621466            $return .= '<span id="change-permalinks"><a href="options-permalink.php" class="button button-small" target="_blank">' . __( 'Change Permalinks' ) . "</a></span>\n";
    14631467        }
     
    16831687        $sendback = admin_url( 'edit.php' );
    16841688
    1685         if ( 'post' != $post->post_type ) {
     1689        if ( 'post' !== $post->post_type ) {
    16861690            $sendback = add_query_arg( 'post_type', $post->post_type, $sendback );
    16871691        }
     
    17011705        $query_args = array();
    17021706        if ( get_post_type_object( $post->post_type )->public ) {
    1703             if ( 'publish' == $post->post_status || $user->ID != $post->post_author ) {
     1707            if ( 'publish' === $post->post_status || $user->ID != $post->post_author ) {
    17041708                // Latest content is in autosave.
    17051709                $nonce                       = wp_create_nonce( 'post_preview_' . $post->ID );
     
    18891893    $is_autosave = false;
    18901894
    1891     if ( ! wp_check_post_lock( $post->ID ) && get_current_user_id() == $post->post_author && ( 'draft' == $post->post_status || 'auto-draft' == $post->post_status ) ) {
     1895    if ( ! wp_check_post_lock( $post->ID ) && get_current_user_id() == $post->post_author
     1896        && ( 'draft' === $post->post_status || 'auto-draft' === $post->post_status )
     1897    ) {
    18921898        $saved_post_id = edit_post();
    18931899    } else {
    18941900        $is_autosave = true;
    18951901
    1896         if ( isset( $_POST['post_status'] ) && 'auto-draft' == $_POST['post_status'] ) {
     1902        if ( isset( $_POST['post_status'] ) && 'auto-draft' === $_POST['post_status'] ) {
    18971903            $_POST['post_status'] = 'draft';
    18981904        }
     
    19541960    }
    19551961
    1956     if ( 'auto-draft' == $post->post_status ) {
     1962    if ( 'auto-draft' === $post->post_status ) {
    19571963        $post_data['post_status'] = 'draft';
    19581964    }
     
    19621968    }
    19631969
    1964     if ( ! wp_check_post_lock( $post->ID ) && get_current_user_id() == $post->post_author && ( 'auto-draft' == $post->post_status || 'draft' == $post->post_status ) ) {
     1970    if ( ! wp_check_post_lock( $post->ID ) && get_current_user_id() == $post->post_author
     1971        && ( 'auto-draft' === $post->post_status || 'draft' === $post->post_status )
     1972    ) {
    19651973        // Drafts and auto-drafts are just overwritten by autosave for the same user if the post is not locked.
    19661974        return edit_post( wp_slash( $post_data ) );
     
    19952003            }
    19962004        } else {
    1997             $message = 'draft' == $status ? 10 : 1;
     2005            $message = 'draft' === $status ? 10 : 1;
    19982006        }
    19992007
Note: See TracChangeset for help on using the changeset viewer.