Skip to content

Commit 0c25783

Browse files
Ignore flood check for notes
1 parent 3b7373b commit 0c25783

File tree

1 file changed

+59
-49
lines changed

1 file changed

+59
-49
lines changed

src/wp-includes/comment.php

Lines changed: 59 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -761,58 +761,68 @@ function wp_allow_comment( $commentdata, $wp_error = false ) {
761761
}
762762
}
763763

764-
/**
765-
* Fires immediately before a comment is marked approved.
766-
*
767-
* Allows checking for comment flooding.
768-
*
769-
* @since 2.3.0
770-
* @since 4.7.0 The `$avoid_die` parameter was added.
771-
* @since 5.5.0 The `$avoid_die` parameter was renamed to `$wp_error`.
772-
*
773-
* @param string $comment_author_ip Comment author's IP address.
774-
* @param string $comment_author_email Comment author's email.
775-
* @param string $comment_date_gmt GMT date the comment was posted.
776-
* @param bool $wp_error Whether to return a WP_Error object instead of executing
777-
* wp_die() or die() if a comment flood is occurring.
778-
*/
779-
do_action(
780-
'check_comment_flood',
781-
$commentdata['comment_author_IP'],
782-
$commentdata['comment_author_email'],
783-
$commentdata['comment_date_gmt'],
784-
$wp_error
785-
);
764+
// Notes require logged in users that can edit the current post, ignore flooding check.
765+
if ( isset( $commentdata['comment_type'] ) && 'note' === $commentdata['comment_type'] ) {
766+
if ( ! is_user_logged_in() ) {
767+
return new WP_Error( 'comment_note_login', __( 'You must be logged in to post a note.' ), 403 );
768+
}
769+
if ( ! current_user_can( 'edit_post', $commentdata['comment_post_ID'] ) ) {
770+
return new WP_Error( 'comment_note_permission', __( 'You do not have permission edit notes on this post.' ), 403 );
771+
}
772+
} else {
773+
/**
774+
* Fires immediately before a comment is marked approved.
775+
*
776+
* Allows checking for comment flooding.
777+
*
778+
* @since 2.3.0
779+
* @since 4.7.0 The `$avoid_die` parameter was added.
780+
* @since 5.5.0 The `$avoid_die` parameter was renamed to `$wp_error`.
781+
*
782+
* @param string $comment_author_ip Comment author's IP address.
783+
* @param string $comment_author_email Comment author's email.
784+
* @param string $comment_date_gmt GMT date the comment was posted.
785+
* @param bool $wp_error Whether to return a WP_Error object instead of executing
786+
* wp_die() or die() if a comment flood is occurring.
787+
*/
788+
do_action(
789+
'check_comment_flood',
790+
$commentdata['comment_author_IP'],
791+
$commentdata['comment_author_email'],
792+
$commentdata['comment_date_gmt'],
793+
$wp_error
794+
);
786795

787-
/**
788-
* Filters whether a comment is part of a comment flood.
789-
*
790-
* The default check is wp_check_comment_flood(). See check_comment_flood_db().
791-
*
792-
* @since 4.7.0
793-
* @since 5.5.0 The `$avoid_die` parameter was renamed to `$wp_error`.
794-
*
795-
* @param bool $is_flood Is a comment flooding occurring? Default false.
796-
* @param string $comment_author_ip Comment author's IP address.
797-
* @param string $comment_author_email Comment author's email.
798-
* @param string $comment_date_gmt GMT date the comment was posted.
799-
* @param bool $wp_error Whether to return a WP_Error object instead of executing
800-
* wp_die() or die() if a comment flood is occurring.
801-
*/
802-
$is_flood = apply_filters(
803-
'wp_is_comment_flood',
804-
false,
805-
$commentdata['comment_author_IP'],
806-
$commentdata['comment_author_email'],
807-
$commentdata['comment_date_gmt'],
808-
$wp_error
809-
);
796+
/**
797+
* Filters whether a comment is part of a comment flood.
798+
*
799+
* The default check is wp_check_comment_flood(). See check_comment_flood_db().
800+
*
801+
* @since 4.7.0
802+
* @since 5.5.0 The `$avoid_die` parameter was renamed to `$wp_error`.
803+
*
804+
* @param bool $is_flood Is a comment flooding occurring? Default false.
805+
* @param string $comment_author_ip Comment author's IP address.
806+
* @param string $comment_author_email Comment author's email.
807+
* @param string $comment_date_gmt GMT date the comment was posted.
808+
* @param bool $wp_error Whether to return a WP_Error object instead of executing
809+
* wp_die() or die() if a comment flood is occurring.
810+
*/
811+
$is_flood = apply_filters(
812+
'wp_is_comment_flood',
813+
false,
814+
$commentdata['comment_author_IP'],
815+
$commentdata['comment_author_email'],
816+
$commentdata['comment_date_gmt'],
817+
$wp_error
818+
);
810819

811-
if ( $is_flood ) {
812-
/** This filter is documented in wp-includes/comment-template.php */
813-
$comment_flood_message = apply_filters( 'comment_flood_message', __( 'You are posting comments too quickly. Slow down.' ) );
820+
if ( $is_flood ) {
821+
/** This filter is documented in wp-includes/comment-template.php */
822+
$comment_flood_message = apply_filters( 'comment_flood_message', __( 'You are posting comments too quickly. Slow down.' ) );
814823

815-
return new WP_Error( 'comment_flood', $comment_flood_message, 429 );
824+
return new WP_Error( 'comment_flood', $comment_flood_message, 429 );
825+
}
816826
}
817827

818828
return wp_check_comment_data( $commentdata );

0 commit comments

Comments
 (0)