From 4f22e04244d85f349bfecd730b7528a2eb70bccb Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Wed, 7 Feb 2018 20:08:47 +0000 Subject: [PATCH] Comments: Introduce 'allow_empty_comment' filter. This filter allows plugin authors to allow empty comments on a selective basis during comment submission. Props jpurdy647. Fixes #16979. git-svn-id: https://develop.svn.wordpress.org/trunk@42661 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/comment.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) 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;