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
This commit is contained in:
Sergey Biryukov 2019-03-21 21:09:47 +00:00
parent e1a070bb87
commit e987281597

View File

@ -687,14 +687,24 @@ function wp_allow_comment( $commentdata, $avoid_die = false ) {
* @param array $commentdata Comment data. * @param array $commentdata Comment data.
*/ */
do_action( 'comment_duplicate_trigger', $commentdata ); 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 ) { 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 { } else {
if ( wp_doing_ajax() ) { 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 ) { 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'] ) ) { 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. * @param int $time_newcomment Timestamp of when the new comment was posted.
*/ */
do_action( 'comment_flood_trigger', $time_lastcomment, $time_newcomment ); do_action( 'comment_flood_trigger', $time_lastcomment, $time_newcomment );
if ( true === $avoid_die ) { if ( true === $avoid_die ) {
return true; return true;
} else { } 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() ) { 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 );
} }
} }
} }