From 3de93dbc991d7733c7fde66d25dcb488d80462ce Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Thu, 21 Mar 2019 21:10:51 +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. Built from https://develop.svn.wordpress.org/trunk@44970 git-svn-id: http://core.svn.wordpress.org/trunk@44801 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/comment.php | 35 +++++++++++++++++++++++++++++------ wp-includes/version.php | 2 +- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/wp-includes/comment.php b/wp-includes/comment.php index d245026d66..1cb9be5ada 100644 --- a/wp-includes/comment.php +++ b/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 ); } } } diff --git a/wp-includes/version.php b/wp-includes/version.php index 18a4f6f739..0e3aa709e1 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.2-alpha-44969'; +$wp_version = '5.2-alpha-44970'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.