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
This commit is contained in:
Sergey Biryukov 2019-03-21 21:10:51 +00:00
parent 19c4841fb6
commit 3de93dbc99
2 changed files with 30 additions and 7 deletions

View File

@ -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 );
}
}
}

View File

@ -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.