WordPress.org

Make WordPress Core

Ticket #16219: garyc40.16219.2.diff

File garyc40.16219.2.diff, 1.4 KB (added by garyc40, 4 years ago)

check is_user_logged_in() as well

  • wp-includes/comment.php

    diff --git wp-includes/comment.php wp-includes/comment.php
    index c0c1756..9fea6a2 100644
    function wp_allow_comment($commentdata) { 
    662662 */ 
    663663function check_comment_flood_db( $ip, $email, $date ) { 
    664664        global $wpdb; 
    665         if ( current_user_can( 'manage_options' ) ) 
     665        if ( current_user_can( 'manage_options' ) || current_user_can( 'moderate_comments' ) ) 
    666666                return; // don't throttle admins 
    667667        $hour_ago = gmdate( 'Y-m-d H:i:s', time() - 3600 ); 
    668         if ( $lasttime = $wpdb->get_var( $wpdb->prepare( "SELECT `comment_date_gmt` FROM `$wpdb->comments` WHERE `comment_date_gmt` >= %s AND ( `comment_author_IP` = %s OR `comment_author_email` = %s ) ORDER BY `comment_date_gmt` DESC LIMIT 1", $hour_ago, $ip, $email ) ) ) { 
     668 
     669        if ( is_user_logged_in() ) { 
     670                $user = get_current_user_id(); 
     671                $check_column = '`user_id`'; 
     672        } else { 
     673                $user = $ip; 
     674                $check_column = '`comment_author_IP`'; 
     675        } 
     676         
     677        if ( $lasttime = $wpdb->get_var( $wpdb->prepare( "SELECT `comment_date_gmt` FROM `$wpdb->comments` WHERE `comment_date_gmt` >= %s AND ( $check_column = %s OR `comment_author_email` = %s ) ORDER BY `comment_date_gmt` DESC LIMIT 1", $hour_ago, $user, $email ) ) ) { 
    669678                $time_lastcomment = mysql2date('U', $lasttime, false); 
    670679                $time_newcomment  = mysql2date('U', $date, false); 
    671680                $flood_die = apply_filters('comment_flood_filter', false, $time_lastcomment, $time_newcomment);