From e987281597173a82bfb53f6f067c53db765eadf6 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Thu, 21 Mar 2019 21:09:47 +0000 Subject: [PATCH] Comments: Introduce `comment_flood_message` and `comment_duplicate_message` filters for comment flood and duplicate comment error messages. Props odminstudios, Katyatina, mukesh27. Fixes #44237. git-svn-id: https://develop.svn.wordpress.org/trunk@44970 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/comment.php | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/src/wp-includes/comment.php b/src/wp-includes/comment.php index d245026d66..1cb9be5ada 100644 --- a/src/wp-includes/comment.php +++ b/src/wp-includes/comment.php @@ -687,14 +687,24 @@ function wp_allow_comment( $commentdata, $avoid_die = false ) { * @param array $commentdata Comment data. */ do_action( 'comment_duplicate_trigger', $commentdata ); + + /** + * Filters duplicate comment error message. + * + * @since 5.2.0 + * + * @param string $comment_duplicate_message Duplicate comment error message. + */ + $comment_duplicate_message = apply_filters( 'comment_duplicate_message', __( 'Duplicate comment detected; it looks as though you’ve already said that!' ) ); + if ( true === $avoid_die ) { - return new WP_Error( 'comment_duplicate', __( 'Duplicate comment detected; it looks as though you’ve already said that!' ), 409 ); + return new WP_Error( 'comment_duplicate', $comment_duplicate_message, 409 ); } else { if ( wp_doing_ajax() ) { - die( __( 'Duplicate comment detected; it looks as though you’ve already said that!' ) ); + die( $comment_duplicate_message ); } - wp_die( __( 'Duplicate comment detected; it looks as though you’ve already said that!' ), 409 ); + wp_die( $comment_duplicate_message, 409 ); } } @@ -744,7 +754,10 @@ function wp_allow_comment( $commentdata, $avoid_die = false ) { ); if ( $is_flood ) { - return new WP_Error( 'comment_flood', __( 'You are posting comments too quickly. Slow down.' ), 429 ); + /** This filter is documented in wp-includes/comment-template.php */ + $comment_flood_message = apply_filters( 'comment_flood_message', __( 'You are posting comments too quickly. Slow down.' ) ); + + return new WP_Error( 'comment_flood', $comment_flood_message, 429 ); } if ( ! empty( $commentdata['user_id'] ) ) { @@ -888,14 +901,24 @@ function wp_check_comment_flood( $is_flood, $ip, $email, $date, $avoid_die = fal * @param int $time_newcomment Timestamp of when the new comment was posted. */ do_action( 'comment_flood_trigger', $time_lastcomment, $time_newcomment ); + if ( true === $avoid_die ) { return true; } else { + /** + * Filters the comment flood error message. + * + * @since 5.2.0 + * + * @param string $comment_flood_message Comment flood error message. + */ + $comment_flood_message = apply_filters( 'comment_flood_message', __( 'You are posting comments too quickly. Slow down.' ) ); + if ( wp_doing_ajax() ) { - die( __( 'You are posting comments too quickly. Slow down.' ) ); + die( $comment_flood_message ); } - wp_die( __( 'You are posting comments too quickly. Slow down.' ), 429 ); + wp_die( $comment_flood_message, 429 ); } } }