Make WordPress Core

Changeset 58287


Ignore:
Timestamp:
06/02/2024 10:08:08 PM (2 years ago)
Author:
SergeyBiryukov
Message:

Coding Standards: Use strict comparison in wp-admin/includes/ajax-actions.php.

Follow-up to [6213], [8296], [8720], [9098], [10204], [10476], [10912], [11644], [11749], [12008], [12036], [13489], [17354], [17832], [18663], [18796], [18937], [22843], [28892], [33356].

Props mujuonly, nihar007, aristath, poena, afercia, SergeyBiryukov.
See #58988, #60700.

Location:
trunk
Files:
3 edited

Legend:

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

    r58105 r58287  
    149149         * ensure it's a non-negative, non-zero integer.
    150150         */
    151         if ( ( 0 == $term_search_min_chars ) || ( strlen( $search ) < $term_search_min_chars ) ) {
     151        if ( ( 0 === $term_search_min_chars ) || ( strlen( $search ) < $term_search_min_chars ) ) {
    152152                wp_die();
    153153        }
     
    206206                $test_str   = '"wpCompressionTest Lorem ipsum dolor sit amet consectetuer mollis sapien urna ut a. Eu nonummy condimentum fringilla tempor pretium platea vel nibh netus Maecenas. Hac molestie amet justo quis pellentesque est ultrices interdum nibh Morbi. Cras mattis pretium Phasellus ante ipsum ipsum ut sociis Suspendisse Lorem. Ante et non molestie. Porta urna Vestibulum egestas id congue nibh eu risus gravida sit. Ac augue auctor Ut et non a elit massa id sodales. Elit eu Nulla at nibh adipiscing mattis lacus mauris at tempus. Netus nibh quis suscipit nec feugiat eget sed lorem et urna. Pellentesque lacus at ut massa consectetuer ligula ut auctor semper Pellentesque. Ut metus massa nibh quam Curabitur molestie nec mauris congue. Volutpat molestie elit justo facilisis neque ac risus Ut nascetur tristique. Vitae sit lorem tellus et quis Phasellus lacus tincidunt nunc Fusce. Pharetra wisi Suspendisse mus sagittis libero lacinia Integer consequat ac Phasellus. Et urna ac cursus tortor aliquam Aliquam amet tellus volutpat Vestibulum. Justo interdum condimentum In augue congue tellus sollicitudin Quisque quis nibh."';
    207207
    208                 if ( 1 == $_GET['test'] ) {
     208                if ( '1' === $_GET['test'] ) {
    209209                        echo $test_str;
    210210                        wp_die();
    211                 } elseif ( 2 == $_GET['test'] ) {
     211                } elseif ( '2' === $_GET['test'] ) {
    212212                        if ( ! isset( $_SERVER['HTTP_ACCEPT_ENCODING'] ) ) {
    213213                                wp_die( -1 );
     
    514514
    515515        // Only do the expensive stuff on a page-break, and about 1 other time per page.
    516         if ( 0 == $total % $per_page || 1 == mt_rand( 1, $per_page ) ) {
     516        if ( 0 === $total % $per_page || 1 === mt_rand( 1, $per_page ) ) {
    517517                $post_id = 0;
    518518                // What type of comment count are we looking for?
     
    734734        $delta  = -1;
    735735
    736         if ( isset( $_POST['trash'] ) && 1 == $_POST['trash'] ) {
     736        if ( isset( $_POST['trash'] ) && '1' === $_POST['trash'] ) {
    737737                if ( 'trash' === $status ) {
    738738                        wp_die( time() );
     
    740740
    741741                $r = wp_trash_comment( $comment );
    742         } elseif ( isset( $_POST['untrash'] ) && 1 == $_POST['untrash'] ) {
     742        } elseif ( isset( $_POST['untrash'] ) && '1' === $_POST['untrash'] ) {
    743743                if ( 'trash' !== $status ) {
    744744                        wp_die( time() );
     
    751751                        $delta = 1;
    752752                }
    753         } elseif ( isset( $_POST['spam'] ) && 1 == $_POST['spam'] ) {
     753        } elseif ( isset( $_POST['spam'] ) && '1' === $_POST['spam'] ) {
    754754                if ( 'spam' === $status ) {
    755755                        wp_die( time() );
     
    757757
    758758                $r = wp_spam_comment( $comment );
    759         } elseif ( isset( $_POST['unspam'] ) && 1 == $_POST['unspam'] ) {
     759        } elseif ( isset( $_POST['unspam'] ) && '1' === $_POST['unspam'] ) {
    760760                if ( 'spam' !== $status ) {
    761761                        wp_die( time() );
     
    768768                        $delta = 1;
    769769                }
    770         } elseif ( isset( $_POST['delete'] ) && 1 == $_POST['delete'] ) {
     770        } elseif ( isset( $_POST['delete'] ) && '1' === $_POST['delete'] ) {
    771771                $r = wp_delete_comment( $comment );
    772772        } else {
     
    10011001        $current = wp_get_comment_status( $comment );
    10021002
    1003         if ( isset( $_POST['new'] ) && $_POST['new'] == $current ) {
     1003        if ( isset( $_POST['new'] ) && $_POST['new'] === $current ) {
    10041004                wp_die( time() );
    10051005        }
     
    13401340                        }
    13411341
    1342                         if ( wp_create_nonce( 'unfiltered-html-comment' ) != $_POST['_wp_unfiltered_html_comment'] ) {
     1342                        if ( wp_create_nonce( 'unfiltered-html-comment' ) !== $_POST['_wp_unfiltered_html_comment'] ) {
    13431343                                kses_remove_filters(); // Start with a clean slate.
    13441344                                kses_init_filters();   // Set up the filters.
     
    13851385                $parent = get_comment( $comment_parent );
    13861386
    1387                 if ( $parent && '0' === $parent->comment_approved && $parent->comment_post_ID == $comment_post_id ) {
     1387                if ( $parent && '0' === $parent->comment_approved && (int) $parent->comment_post_ID === $comment_post_id ) {
    13881388                        if ( ! current_user_can( 'edit_comment', $parent->comment_ID ) ) {
    13891389                                wp_die( -1 );
     
    14831483        }
    14841484
    1485         $position      = ( isset( $_POST['position'] ) && (int) $_POST['position'] ) ? (int) $_POST['position'] : '-1';
    1486         $checkbox      = ( isset( $_POST['checkbox'] ) && true == $_POST['checkbox'] ) ? 1 : 0;
     1485        $position = ( isset( $_POST['position'] ) && (int) $_POST['position'] ) ? (int) $_POST['position'] : '-1';
     1486        /*
     1487         * Checkbox is used to differentiate between the Edit Comments screen (1)
     1488         * and the Comments section on the Edit Post screen (0).
     1489         */
     1490        $checkbox      = ( isset( $_POST['checkbox'] ) && '1' === $_POST['checkbox'] ) ? 1 : 0;
    14871491        $wp_list_table = _get_list_table( $checkbox ? 'WP_Comments_List_Table' : 'WP_Post_Comments_List_Table', array( 'screen' => 'edit-comments' ) );
    14881492
     
    17001704                }
    17011705
    1702                 if ( $meta->meta_value != $value || $meta->meta_key != $key ) {
     1706                if ( $meta->meta_value !== $value || $meta->meta_key !== $key ) {
    17031707                        $u = update_metadata_by_mid( 'post', $mid, $value, $key );
    17041708                        if ( ! $u ) {
     
    17981802        $page = isset( $_POST['page'] ) ? $_POST['page'] : '';
    17991803
    1800         if ( sanitize_key( $page ) != $page ) {
     1804        if ( sanitize_key( $page ) !== $page ) {
    18011805                wp_die( 0 );
    18021806        }
     
    18291833        $page = isset( $_POST['page'] ) ? $_POST['page'] : '';
    18301834
    1831         if ( sanitize_key( $page ) != $page ) {
     1835        if ( sanitize_key( $page ) !== $page ) {
    18321836                wp_die( 0 );
    18331837        }
     
    19841988        $page = isset( $_POST['page'] ) ? $_POST['page'] : '';
    19851989
    1986         if ( sanitize_key( $page ) != $page ) {
     1990        if ( sanitize_key( $page ) !== $page ) {
    19871991                wp_die( 0 );
    19881992        }
     
    24132417        foreach ( (array) $wp_registered_widget_updates as $name => $control ) {
    24142418
    2415                 if ( $name == $id_base ) {
     2419                if ( $name === $id_base ) {
    24162420                        if ( ! is_callable( $control['callback'] ) ) {
    24172421                                continue;
     
    27432747        }
    27442748
    2745         if ( '-1' == $thumbnail_id ) {
     2749        if ( -1 === $thumbnail_id ) {
    27462750                if ( delete_post_thumbnail( $post_id ) ) {
    27472751                        $return = _wp_post_thumbnail_html( null, $post_id );
     
    29272931        $active_lock = array_map( 'absint', explode( ':', $_POST['active_post_lock'] ) );
    29282932
    2929         if ( get_current_user_id() != $active_lock[1] ) {
     2933        if ( get_current_user_id() !== $active_lock[1] ) {
    29302934                wp_die( 0 );
    29312935        }
     
    29522956        $pointer = $_POST['pointer'];
    29532957
    2954         if ( sanitize_key( $pointer ) != $pointer ) {
     2958        if ( sanitize_key( $pointer ) !== $pointer ) {
    29552959                wp_die( 0 );
    29562960        }
     
    33243328                $insert_into_post_id = (int) $_POST['post_id'];
    33253329
    3326                 if ( 0 == $post->post_parent && $insert_into_post_id ) {
     3330                if ( 0 === $post->post_parent && $insert_into_post_id ) {
    33273331                        wp_update_post(
    33283332                                array(
     
    40254029
    40264030                        // Skip creating a new attachment if the attachment is a Site Icon.
    4027                         if ( get_post_meta( $attachment_id, '_wp_attachment_context', true ) == $context ) {
     4031                        if ( get_post_meta( $attachment_id, '_wp_attachment_context', true ) === $context ) {
    40284032
    40294033                                // Delete the temporary cropped file, we don't need it.
  • trunk/tests/phpunit/tests/ajax/wpAjaxDeleteComment.php

    r54722 r58287  
    7777                $_POST['id']          = $comment->comment_ID;
    7878                $_POST['_ajax_nonce'] = wp_create_nonce( 'delete-comment_' . $comment->comment_ID );
    79                 $_POST[ $action ]     = 1;
    80                 $_POST['_total']      = count( self::$comments );
    81                 $_POST['_per_page']   = 100;
    82                 $_POST['_page']       = 1;
     79                $_POST[ $action ]     = '1';
     80                $_POST['_total']      = count( self::$comments );
     81                $_POST['_per_page']   = '100';
     82                $_POST['_page']       = '1';
    8383                $_POST['_url']        = admin_url( 'edit-comments.php' );
    8484
     
    136136                $_POST['id']          = $comment->comment_ID;
    137137                $_POST['_ajax_nonce'] = wp_create_nonce( 'delete-comment_' . $comment->comment_ID );
    138                 $_POST[ $action ]     = 1;
    139                 $_POST['_total']      = count( self::$comments );
    140                 $_POST['_per_page']   = 100;
    141                 $_POST['_page']       = 1;
     138                $_POST[ $action ]     = '1';
     139                $_POST['_total']      = count( self::$comments );
     140                $_POST['_per_page']   = '100';
     141                $_POST['_page']       = '1';
    142142                $_POST['_url']        = admin_url( 'edit-comments.php' );
    143143
     
    168168                $_POST['id']          = $comment->comment_ID;
    169169                $_POST['_ajax_nonce'] = wp_create_nonce( uniqid() );
    170                 $_POST[ $action ]     = 1;
    171                 $_POST['_total']      = count( self::$comments );
    172                 $_POST['_per_page']   = 100;
    173                 $_POST['_page']       = 1;
     170                $_POST[ $action ]     = '1';
     171                $_POST['_total']      = count( self::$comments );
     172                $_POST['_per_page']   = '100';
     173                $_POST['_page']       = '1';
    174174                $_POST['_url']        = admin_url( 'edit-comments.php' );
    175175
     
    199199                $_POST['id']          = 12346789;
    200200                $_POST['_ajax_nonce'] = wp_create_nonce( 'delete-comment_12346789' );
    201                 $_POST[ $action ]     = 1;
    202                 $_POST['_total']      = count( self::$comments );
    203                 $_POST['_per_page']   = 100;
    204                 $_POST['_page']       = 1;
     201                $_POST[ $action ]     = '1';
     202                $_POST['_total']      = count( self::$comments );
     203                $_POST['_per_page']   = '100';
     204                $_POST['_page']       = '1';
    205205                $_POST['_url']        = admin_url( 'edit-comments.php' );
    206206
     
    236236                $_POST['id']          = $comment->comment_ID;
    237237                $_POST['_ajax_nonce'] = wp_create_nonce( 'delete-comment_' . $comment->comment_ID );
    238                 $_POST[ $action ]     = 1;
    239                 $_POST['_total']      = count( self::$comments );
    240                 $_POST['_per_page']   = 100;
    241                 $_POST['_page']       = 1;
     238                $_POST[ $action ]     = '1';
     239                $_POST['_total']      = count( self::$comments );
     240                $_POST['_per_page']   = '100';
     241                $_POST['_page']       = '1';
    242242                $_POST['_url']        = admin_url( 'edit-comments.php' );
    243243
  • trunk/tests/phpunit/tests/ajax/wpAjaxWpCompressionTest.php

    r54722 r58287  
    2626
    2727                // Set up a default request.
    28                 $_GET['test'] = 1;
     28                $_GET['test'] = '1';
    2929
    3030                // Make the request.
     
    4343
    4444                // Set up a default request.
    45                 $_GET['test'] = 1;
     45                $_GET['test'] = '1';
    4646
    4747                // Make the request.
     
    6767
    6868                // Set up a default request.
    69                 $_GET['test']                    = 2;
     69                $_GET['test'] = '2';
     70
    7071                $_SERVER['HTTP_ACCEPT_ENCODING'] = 'deflate';
    7172
     
    9293
    9394                // Set up a default request.
    94                 $_GET['test']                    = 2;
     95                $_GET['test'] = '2';
     96
    9597                $_SERVER['HTTP_ACCEPT_ENCODING'] = 'gzip';
    9698
     
    115117
    116118                // Set up a default request.
    117                 $_GET['test']                    = 2;
     119                $_GET['test'] = '2';
     120
    118121                $_SERVER['HTTP_ACCEPT_ENCODING'] = 'unknown';
    119122
Note: See TracChangeset for help on using the changeset viewer.