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.
Built from https://develop.svn.wordpress.org/trunk@58287


git-svn-id: http://core.svn.wordpress.org/trunk@57747 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2024-06-02 22:10:11 +00:00
parent d82ab90019
commit 6c8e2bcb90
2 changed files with 29 additions and 25 deletions

View File

@ -148,7 +148,7 @@ function wp_ajax_ajax_tag_search() {
* Require $term_search_min_chars chars for matching (default: 2) * Require $term_search_min_chars chars for matching (default: 2)
* ensure it's a non-negative, non-zero integer. * ensure it's a non-negative, non-zero integer.
*/ */
if ( ( 0 == $term_search_min_chars ) || ( strlen( $search ) < $term_search_min_chars ) ) { if ( ( 0 === $term_search_min_chars ) || ( strlen( $search ) < $term_search_min_chars ) ) {
wp_die(); wp_die();
} }
@ -205,10 +205,10 @@ function wp_ajax_wp_compression_test() {
$force_gzip = ( defined( 'ENFORCE_GZIP' ) && ENFORCE_GZIP ); $force_gzip = ( defined( 'ENFORCE_GZIP' ) && ENFORCE_GZIP );
$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."'; $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."';
if ( 1 == $_GET['test'] ) { if ( '1' === $_GET['test'] ) {
echo $test_str; echo $test_str;
wp_die(); wp_die();
} elseif ( 2 == $_GET['test'] ) { } elseif ( '2' === $_GET['test'] ) {
if ( ! isset( $_SERVER['HTTP_ACCEPT_ENCODING'] ) ) { if ( ! isset( $_SERVER['HTTP_ACCEPT_ENCODING'] ) ) {
wp_die( -1 ); wp_die( -1 );
} }
@ -513,7 +513,7 @@ function _wp_ajax_delete_comment_response( $comment_id, $delta = -1 ) {
} }
// Only do the expensive stuff on a page-break, and about 1 other time per page. // Only do the expensive stuff on a page-break, and about 1 other time per page.
if ( 0 == $total % $per_page || 1 == mt_rand( 1, $per_page ) ) { if ( 0 === $total % $per_page || 1 === mt_rand( 1, $per_page ) ) {
$post_id = 0; $post_id = 0;
// What type of comment count are we looking for? // What type of comment count are we looking for?
$status = 'all'; $status = 'all';
@ -733,13 +733,13 @@ function wp_ajax_delete_comment() {
$status = wp_get_comment_status( $comment ); $status = wp_get_comment_status( $comment );
$delta = -1; $delta = -1;
if ( isset( $_POST['trash'] ) && 1 == $_POST['trash'] ) { if ( isset( $_POST['trash'] ) && '1' === $_POST['trash'] ) {
if ( 'trash' === $status ) { if ( 'trash' === $status ) {
wp_die( time() ); wp_die( time() );
} }
$r = wp_trash_comment( $comment ); $r = wp_trash_comment( $comment );
} elseif ( isset( $_POST['untrash'] ) && 1 == $_POST['untrash'] ) { } elseif ( isset( $_POST['untrash'] ) && '1' === $_POST['untrash'] ) {
if ( 'trash' !== $status ) { if ( 'trash' !== $status ) {
wp_die( time() ); wp_die( time() );
} }
@ -750,13 +750,13 @@ function wp_ajax_delete_comment() {
if ( ! isset( $_POST['comment_status'] ) || 'trash' !== $_POST['comment_status'] ) { if ( ! isset( $_POST['comment_status'] ) || 'trash' !== $_POST['comment_status'] ) {
$delta = 1; $delta = 1;
} }
} elseif ( isset( $_POST['spam'] ) && 1 == $_POST['spam'] ) { } elseif ( isset( $_POST['spam'] ) && '1' === $_POST['spam'] ) {
if ( 'spam' === $status ) { if ( 'spam' === $status ) {
wp_die( time() ); wp_die( time() );
} }
$r = wp_spam_comment( $comment ); $r = wp_spam_comment( $comment );
} elseif ( isset( $_POST['unspam'] ) && 1 == $_POST['unspam'] ) { } elseif ( isset( $_POST['unspam'] ) && '1' === $_POST['unspam'] ) {
if ( 'spam' !== $status ) { if ( 'spam' !== $status ) {
wp_die( time() ); wp_die( time() );
} }
@ -767,7 +767,7 @@ function wp_ajax_delete_comment() {
if ( ! isset( $_POST['comment_status'] ) || 'spam' !== $_POST['comment_status'] ) { if ( ! isset( $_POST['comment_status'] ) || 'spam' !== $_POST['comment_status'] ) {
$delta = 1; $delta = 1;
} }
} elseif ( isset( $_POST['delete'] ) && 1 == $_POST['delete'] ) { } elseif ( isset( $_POST['delete'] ) && '1' === $_POST['delete'] ) {
$r = wp_delete_comment( $comment ); $r = wp_delete_comment( $comment );
} else { } else {
wp_die( -1 ); wp_die( -1 );
@ -1000,7 +1000,7 @@ function wp_ajax_dim_comment() {
$current = wp_get_comment_status( $comment ); $current = wp_get_comment_status( $comment );
if ( isset( $_POST['new'] ) && $_POST['new'] == $current ) { if ( isset( $_POST['new'] ) && $_POST['new'] === $current ) {
wp_die( time() ); wp_die( time() );
} }
@ -1339,7 +1339,7 @@ function wp_ajax_replyto_comment( $action ) {
$_POST['_wp_unfiltered_html_comment'] = ''; $_POST['_wp_unfiltered_html_comment'] = '';
} }
if ( wp_create_nonce( 'unfiltered-html-comment' ) != $_POST['_wp_unfiltered_html_comment'] ) { if ( wp_create_nonce( 'unfiltered-html-comment' ) !== $_POST['_wp_unfiltered_html_comment'] ) {
kses_remove_filters(); // Start with a clean slate. kses_remove_filters(); // Start with a clean slate.
kses_init_filters(); // Set up the filters. kses_init_filters(); // Set up the filters.
remove_filter( 'pre_comment_content', 'wp_filter_post_kses' ); remove_filter( 'pre_comment_content', 'wp_filter_post_kses' );
@ -1384,7 +1384,7 @@ function wp_ajax_replyto_comment( $action ) {
if ( ! empty( $_POST['approve_parent'] ) ) { if ( ! empty( $_POST['approve_parent'] ) ) {
$parent = get_comment( $comment_parent ); $parent = get_comment( $comment_parent );
if ( $parent && '0' === $parent->comment_approved && $parent->comment_post_ID == $comment_post_id ) { if ( $parent && '0' === $parent->comment_approved && (int) $parent->comment_post_ID === $comment_post_id ) {
if ( ! current_user_can( 'edit_comment', $parent->comment_ID ) ) { if ( ! current_user_can( 'edit_comment', $parent->comment_ID ) ) {
wp_die( -1 ); wp_die( -1 );
} }
@ -1482,8 +1482,12 @@ function wp_ajax_edit_comment() {
wp_die( $updated->get_error_message() ); wp_die( $updated->get_error_message() );
} }
$position = ( isset( $_POST['position'] ) && (int) $_POST['position'] ) ? (int) $_POST['position'] : '-1'; $position = ( isset( $_POST['position'] ) && (int) $_POST['position'] ) ? (int) $_POST['position'] : '-1';
$checkbox = ( isset( $_POST['checkbox'] ) && true == $_POST['checkbox'] ) ? 1 : 0; /*
* Checkbox is used to differentiate between the Edit Comments screen (1)
* and the Comments section on the Edit Post screen (0).
*/
$checkbox = ( isset( $_POST['checkbox'] ) && '1' === $_POST['checkbox'] ) ? 1 : 0;
$wp_list_table = _get_list_table( $checkbox ? 'WP_Comments_List_Table' : 'WP_Post_Comments_List_Table', array( 'screen' => 'edit-comments' ) ); $wp_list_table = _get_list_table( $checkbox ? 'WP_Comments_List_Table' : 'WP_Post_Comments_List_Table', array( 'screen' => 'edit-comments' ) );
$comment = get_comment( $comment_id ); $comment = get_comment( $comment_id );
@ -1699,7 +1703,7 @@ function wp_ajax_add_meta() {
wp_die( -1 ); wp_die( -1 );
} }
if ( $meta->meta_value != $value || $meta->meta_key != $key ) { if ( $meta->meta_value !== $value || $meta->meta_key !== $key ) {
$u = update_metadata_by_mid( 'post', $mid, $value, $key ); $u = update_metadata_by_mid( 'post', $mid, $value, $key );
if ( ! $u ) { if ( ! $u ) {
wp_die( 0 ); // We know meta exists; we also know it's unchanged (or DB error, in which case there are bigger problems). wp_die( 0 ); // We know meta exists; we also know it's unchanged (or DB error, in which case there are bigger problems).
@ -1797,7 +1801,7 @@ function wp_ajax_closed_postboxes() {
$page = isset( $_POST['page'] ) ? $_POST['page'] : ''; $page = isset( $_POST['page'] ) ? $_POST['page'] : '';
if ( sanitize_key( $page ) != $page ) { if ( sanitize_key( $page ) !== $page ) {
wp_die( 0 ); wp_die( 0 );
} }
@ -1828,7 +1832,7 @@ function wp_ajax_hidden_columns() {
check_ajax_referer( 'screen-options-nonce', 'screenoptionnonce' ); check_ajax_referer( 'screen-options-nonce', 'screenoptionnonce' );
$page = isset( $_POST['page'] ) ? $_POST['page'] : ''; $page = isset( $_POST['page'] ) ? $_POST['page'] : '';
if ( sanitize_key( $page ) != $page ) { if ( sanitize_key( $page ) !== $page ) {
wp_die( 0 ); wp_die( 0 );
} }
@ -1983,7 +1987,7 @@ function wp_ajax_meta_box_order() {
$page = isset( $_POST['page'] ) ? $_POST['page'] : ''; $page = isset( $_POST['page'] ) ? $_POST['page'] : '';
if ( sanitize_key( $page ) != $page ) { if ( sanitize_key( $page ) !== $page ) {
wp_die( 0 ); wp_die( 0 );
} }
@ -2412,7 +2416,7 @@ function wp_ajax_save_widget() {
foreach ( (array) $wp_registered_widget_updates as $name => $control ) { foreach ( (array) $wp_registered_widget_updates as $name => $control ) {
if ( $name == $id_base ) { if ( $name === $id_base ) {
if ( ! is_callable( $control['callback'] ) ) { if ( ! is_callable( $control['callback'] ) ) {
continue; continue;
} }
@ -2742,7 +2746,7 @@ function wp_ajax_set_post_thumbnail() {
check_ajax_referer( "set_post_thumbnail-$post_id" ); check_ajax_referer( "set_post_thumbnail-$post_id" );
} }
if ( '-1' == $thumbnail_id ) { if ( -1 === $thumbnail_id ) {
if ( delete_post_thumbnail( $post_id ) ) { if ( delete_post_thumbnail( $post_id ) ) {
$return = _wp_post_thumbnail_html( null, $post_id ); $return = _wp_post_thumbnail_html( null, $post_id );
$json ? wp_send_json_success( $return ) : wp_die( $return ); $json ? wp_send_json_success( $return ) : wp_die( $return );
@ -2926,7 +2930,7 @@ function wp_ajax_wp_remove_post_lock() {
$active_lock = array_map( 'absint', explode( ':', $_POST['active_post_lock'] ) ); $active_lock = array_map( 'absint', explode( ':', $_POST['active_post_lock'] ) );
if ( get_current_user_id() != $active_lock[1] ) { if ( get_current_user_id() !== $active_lock[1] ) {
wp_die( 0 ); wp_die( 0 );
} }
@ -2951,7 +2955,7 @@ function wp_ajax_wp_remove_post_lock() {
function wp_ajax_dismiss_wp_pointer() { function wp_ajax_dismiss_wp_pointer() {
$pointer = $_POST['pointer']; $pointer = $_POST['pointer'];
if ( sanitize_key( $pointer ) != $pointer ) { if ( sanitize_key( $pointer ) !== $pointer ) {
wp_die( 0 ); wp_die( 0 );
} }
@ -3323,7 +3327,7 @@ function wp_ajax_send_attachment_to_editor() {
// If this attachment is unattached, attach it. Primarily a back compat thing. // If this attachment is unattached, attach it. Primarily a back compat thing.
$insert_into_post_id = (int) $_POST['post_id']; $insert_into_post_id = (int) $_POST['post_id'];
if ( 0 == $post->post_parent && $insert_into_post_id ) { if ( 0 === $post->post_parent && $insert_into_post_id ) {
wp_update_post( wp_update_post(
array( array(
'ID' => $id, 'ID' => $id,
@ -4024,7 +4028,7 @@ function wp_ajax_crop_image() {
$wp_site_icon = new WP_Site_Icon(); $wp_site_icon = new WP_Site_Icon();
// Skip creating a new attachment if the attachment is a Site Icon. // Skip creating a new attachment if the attachment is a Site Icon.
if ( get_post_meta( $attachment_id, '_wp_attachment_context', true ) == $context ) { if ( get_post_meta( $attachment_id, '_wp_attachment_context', true ) === $context ) {
// Delete the temporary cropped file, we don't need it. // Delete the temporary cropped file, we don't need it.
wp_delete_file( $cropped ); wp_delete_file( $cropped );

View File

@ -16,7 +16,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '6.6-alpha-58286'; $wp_version = '6.6-alpha-58287';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.