Make WordPress Core

Ticket #61827: 61827.diff

File 61827.diff, 3.7 KB (added by SergeyBiryukov, 8 months ago)
  • src/wp-includes/comment.php

     
    773773                return new WP_Error( 'comment_flood', $comment_flood_message, 429 );
    774774        }
    775775
    776         if ( ! empty( $commentdata['user_id'] ) ) {
    777                 $user        = get_userdata( $commentdata['user_id'] );
    778                 $post_author = $wpdb->get_var(
    779                         $wpdb->prepare(
    780                                 "SELECT post_author FROM $wpdb->posts WHERE ID = %d LIMIT 1",
    781                                 $commentdata['comment_post_ID']
    782                         )
    783                 );
    784         }
     776        $approved = wp_check_comment_data( $commentdata );
    785777
    786         if ( isset( $user ) && ( $commentdata['user_id'] == $post_author || $user->has_cap( 'moderate_comments' ) ) ) {
    787                 // The author and the admins get respect.
    788                 $approved = 1;
    789         } else {
    790                 // Everyone else's comments will be checked.
    791                 if ( check_comment(
    792                         $commentdata['comment_author'],
    793                         $commentdata['comment_author_email'],
    794                         $commentdata['comment_author_url'],
    795                         $commentdata['comment_content'],
    796                         $commentdata['comment_author_IP'],
    797                         $commentdata['comment_agent'],
    798                         $commentdata['comment_type']
    799                 ) ) {
    800                         $approved = 1;
    801                 } else {
    802                         $approved = 0;
    803                 }
    804 
    805                 if ( wp_check_comment_disallowed_list(
    806                         $commentdata['comment_author'],
    807                         $commentdata['comment_author_email'],
    808                         $commentdata['comment_author_url'],
    809                         $commentdata['comment_content'],
    810                         $commentdata['comment_author_IP'],
    811                         $commentdata['comment_agent']
    812                 ) ) {
    813                         $approved = EMPTY_TRASH_DAYS ? 'trash' : 'spam';
    814                 }
    815         }
    816 
    817778        /**
    818779         * Filters a comment's approval status before it is set.
    819780         *
     
    12931254}
    12941255
    12951256/**
     1257 * Checks whether comment data passes internal checks or has disallowed content.
     1258 *
     1259 * @since 6.7.0
     1260 *
     1261 * @global wpdb $wpdb WordPress database abstraction object.
     1262 *
     1263 * @param array $comment_data Array of arguments for inserting a comment.
     1264 * @return int|string The approval status (0|1|'spam'|'trash').
     1265 */
     1266function wp_check_comment_data( $comment_data ) {
     1267        global $wpdb;
     1268
     1269        if ( ! empty( $comment_data['user_id'] ) ) {
     1270                $user        = get_userdata( $comment_data['user_id'] );
     1271                $post_author = $wpdb->get_var(
     1272                        $wpdb->prepare(
     1273                                "SELECT post_author FROM $wpdb->posts WHERE ID = %d LIMIT 1",
     1274                                $comment_data['comment_post_ID']
     1275                        )
     1276                );
     1277        }
     1278
     1279        if ( isset( $user ) && ( $comment_data['user_id'] == $post_author || $user->has_cap( 'moderate_comments' ) ) ) {
     1280                // The author and the admins get respect.
     1281                $approved = 1;
     1282        } else {
     1283                // Everyone else's comments will be checked.
     1284                if ( check_comment(
     1285                        $comment_data['comment_author'],
     1286                        $comment_data['comment_author_email'],
     1287                        $comment_data['comment_author_url'],
     1288                        $comment_data['comment_content'],
     1289                        $comment_data['comment_author_IP'],
     1290                        $comment_data['comment_agent'],
     1291                        $comment_data['comment_type']
     1292                ) ) {
     1293                        $approved = 1;
     1294                } else {
     1295                        $approved = 0;
     1296                }
     1297
     1298                if ( wp_check_comment_disallowed_list(
     1299                        $comment_data['comment_author'],
     1300                        $comment_data['comment_author_email'],
     1301                        $comment_data['comment_author_url'],
     1302                        $comment_data['comment_content'],
     1303                        $comment_data['comment_author_IP'],
     1304                        $comment_data['comment_agent']
     1305                ) ) {
     1306                        $approved = EMPTY_TRASH_DAYS ? 'trash' : 'spam';
     1307                }
     1308        }
     1309
     1310        return $approved;
     1311}
     1312
     1313/**
    12961314 * Checks if a comment contains disallowed characters or words.
    12971315 *
    12981316 * @since 5.5.0
     
    22832301
    22842302        if ( ! in_array( $commentdata['comment_approved'], array( 'trash', 'spam' ), true ) ) {
    22852303                // Validate the comment again after filters are applied to comment data.
    2286                 $commentdata['comment_approved'] = wp_allow_comment( $commentdata, $wp_error );
     2304                $commentdata['comment_approved'] = wp_check_comment_data( $commentdata );
    22872305        }
    22882306
    22892307        if ( is_wp_error( $commentdata['comment_approved'] ) ) {