From f01ff83ac372867253e4e757c5843add4ef83bd9 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sun, 9 Mar 2025 23:02:41 +0000 Subject: [PATCH] Coding Standards: Use strict comparison in `check_comment()`. Follow-up to [1012], [1737], [48121]. Props aristath, poena, afercia, SergeyBiryukov. See #62279. git-svn-id: https://develop.svn.wordpress.org/trunk@59957 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/comment.php | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/src/wp-includes/comment.php b/src/wp-includes/comment.php index 7a824f5b07..8d05be9063 100644 --- a/src/wp-includes/comment.php +++ b/src/wp-includes/comment.php @@ -40,7 +40,7 @@ function check_comment( $author, $email, $url, $comment, $user_ip, $user_agent, global $wpdb; // If manual moderation is enabled, skip all checks and return false. - if ( 1 == get_option( 'comment_moderation' ) ) { + if ( '1' === get_option( 'comment_moderation' ) ) { return false; } @@ -126,18 +126,38 @@ function check_comment( $author, $email, $url, $comment, $user_ip, $user_agent, * as well as whether there are any moderation keywords (if set) present in the author * email address. If both checks pass, return true. Otherwise, return false. */ - if ( 1 == get_option( 'comment_previously_approved' ) ) { + if ( '1' === get_option( 'comment_previously_approved' ) ) { if ( 'trackback' !== $comment_type && 'pingback' !== $comment_type && '' !== $author && '' !== $email ) { $comment_user = get_user_by( 'email', wp_unslash( $email ) ); if ( ! empty( $comment_user->ID ) ) { - $ok_to_comment = $wpdb->get_var( $wpdb->prepare( "SELECT comment_approved FROM $wpdb->comments WHERE user_id = %d AND comment_approved = '1' LIMIT 1", $comment_user->ID ) ); + $ok_to_comment = $wpdb->get_var( + $wpdb->prepare( + "SELECT comment_approved + FROM $wpdb->comments + WHERE user_id = %d + AND comment_approved = '1' + LIMIT 1", + $comment_user->ID + ) + ); } else { // expected_slashed ($author, $email) - $ok_to_comment = $wpdb->get_var( $wpdb->prepare( "SELECT comment_approved FROM $wpdb->comments WHERE comment_author = %s AND comment_author_email = %s and comment_approved = '1' LIMIT 1", $author, $email ) ); + $ok_to_comment = $wpdb->get_var( + $wpdb->prepare( + "SELECT comment_approved + FROM $wpdb->comments + WHERE comment_author = %s + AND comment_author_email = %s + AND comment_approved = '1' + LIMIT 1", + $author, + $email + ) + ); } - if ( ( 1 == $ok_to_comment ) && - ( empty( $mod_keys ) || ! str_contains( $email, $mod_keys ) ) ) { - return true; + + if ( '1' === $ok_to_comment && ( empty( $mod_keys ) || ! str_contains( $email, $mod_keys ) ) ) { + return true; } else { return false; }