/*
* Check if the option to approve comments by previously-approved authors is enabled.
*
* If it is enabled, check whether the comment author has a previously-approved comment,
* 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 ( '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
) );
} 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 ) );
} if ( ( 1 ==
$ok_to_comment ) && ( empty( $mod_keys ) || !
str_contains( $email,
$mod_keys ) ) ) { return true;
} else { return false;
}