Make WordPress Core

Ticket #61827: 61827.2.diff

File 61827.2.diff, 4.9 KB (added by david.binda, 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         }
    785 
    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 
    817         /**
    818          * Filters a comment's approval status before it is set.
    819          *
    820          * @since 2.1.0
    821          * @since 4.9.0 Returning a WP_Error value from the filter will short-circuit comment insertion
    822          *              and allow skipping further processing.
    823          *
    824          * @param int|string|WP_Error $approved    The approval status. Accepts 1, 0, 'spam', 'trash',
    825          *                                         or WP_Error.
    826          * @param array               $commentdata Comment data.
    827          */
    828         return apply_filters( 'pre_comment_approved', $approved, $commentdata );
     776        return wp_check_comment_data( $commentdata );
    829777}
    830778
    831779/**
     
    12931241}
    12941242
    12951243/**
     1244 * Checks whether comment data passes internal checks or has disallowed content.
     1245 *
     1246 * @since 6.7.0
     1247 *
     1248 * @global wpdb $wpdb WordPress database abstraction object.
     1249 *
     1250 * @param array $comment_data Array of arguments for inserting a comment.
     1251 * @return int|string The approval status (0|1|'spam'|'trash').
     1252 */
     1253function wp_check_comment_data( $comment_data ) {
     1254        global $wpdb;
     1255
     1256        if ( ! empty( $comment_data['user_id'] ) ) {
     1257                $user        = get_userdata( $comment_data['user_id'] );
     1258                $post_author = $wpdb->get_var(
     1259                        $wpdb->prepare(
     1260                                "SELECT post_author FROM $wpdb->posts WHERE ID = %d LIMIT 1",
     1261                                $comment_data['comment_post_ID']
     1262                        )
     1263                );
     1264        }
     1265
     1266        if ( isset( $user ) && ( $comment_data['user_id'] == $post_author || $user->has_cap( 'moderate_comments' ) ) ) {
     1267                // The author and the admins get respect.
     1268                $approved = 1;
     1269        } else {
     1270                // Everyone else's comments will be checked.
     1271                if ( check_comment(
     1272                        $comment_data['comment_author'],
     1273                        $comment_data['comment_author_email'],
     1274                        $comment_data['comment_author_url'],
     1275                        $comment_data['comment_content'],
     1276                        $comment_data['comment_author_IP'],
     1277                        $comment_data['comment_agent'],
     1278                        $comment_data['comment_type']
     1279                ) ) {
     1280                        $approved = 1;
     1281                } else {
     1282                        $approved = 0;
     1283                }
     1284
     1285                if ( wp_check_comment_disallowed_list(
     1286                        $comment_data['comment_author'],
     1287                        $comment_data['comment_author_email'],
     1288                        $comment_data['comment_author_url'],
     1289                        $comment_data['comment_content'],
     1290                        $comment_data['comment_author_IP'],
     1291                        $comment_data['comment_agent']
     1292                ) ) {
     1293                        $approved = EMPTY_TRASH_DAYS ? 'trash' : 'spam';
     1294                }
     1295        }
     1296
     1297        /**
     1298         * Filters a comment's approval status before it is set.
     1299         *
     1300         * @since 2.1.0
     1301         * @since 4.9.0 Returning a WP_Error value from the filter will short-circuit comment insertion
     1302         *              and allow skipping further processing.
     1303         *
     1304         * @param int|string|WP_Error $approved    The approval status. Accepts 1, 0, 'spam', 'trash',
     1305         *                                         or WP_Error.
     1306         * @param array               $commentdata Comment data.
     1307         */
     1308        return apply_filters( 'pre_comment_approved', $approved, $comment_data );
     1309}
     1310
     1311/**
    12961312 * Checks if a comment contains disallowed characters or words.
    12971313 *
    12981314 * @since 5.5.0
     
    22792295
    22802296        $commentdata['comment_approved'] = wp_allow_comment( $commentdata, $wp_error );
    22812297
     2298        if ( is_wp_error( $commentdata['comment_approved'] ) ) {
     2299                return $commentdata['comment_approved'];
     2300        }
     2301
    22822302        $commentdata = wp_filter_comment( $commentdata );
    22832303
    22842304        if ( ! in_array( $commentdata['comment_approved'], array( 'trash', 'spam' ), true ) ) {
    22852305                // Validate the comment again after filters are applied to comment data.
    2286                 $commentdata['comment_approved'] = wp_allow_comment( $commentdata, $wp_error );
     2306                $commentdata['comment_approved'] = wp_check_comment_data( $commentdata );
    22872307        }
    22882308
    22892309        if ( is_wp_error( $commentdata['comment_approved'] ) ) {