diff --git a/src/wp-includes/comment.php b/src/wp-includes/comment.php
index c134aadcd0..e2c5ccbd3c 100644
--- a/src/wp-includes/comment.php
+++ b/src/wp-includes/comment.php
@@ -3222,10 +3222,6 @@ function wp_handle_comment_submission( $comment_data ) {
}
}
- if ( '' == $comment_content ) {
- return new WP_Error( 'require_valid_comment', __( 'ERROR: please type a comment.' ), 200 );
- }
-
$commentdata = compact(
'comment_post_ID',
'comment_author',
@@ -3237,6 +3233,19 @@ function wp_handle_comment_submission( $comment_data ) {
'user_ID'
);
+ /**
+ * Filters whether an empty comment should be allowed.
+ *
+ * @since 5.0.0
+ *
+ * @param bool $allow_empty_comment Default false.
+ * @param array $commentdata Array of comment data to be sent to wp_insert_comment().
+ */
+ $allow_empty_comment = apply_filters( 'allow_empty_comment', false, $commentdata );
+ if ( '' === $comment_content && ! $allow_empty_comment ) {
+ return new WP_Error( 'require_valid_comment', __( 'ERROR: please type a comment.' ), 200 );
+ }
+
$check_max_lengths = wp_check_comment_data_max_lengths( $commentdata );
if ( is_wp_error( $check_max_lengths ) ) {
return $check_max_lengths;