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
This commit is contained in:
Boone Gorges 2018-02-07 20:08:47 +00:00
parent 602117f2b9
commit 4f22e04244
1 changed files with 13 additions and 4 deletions

View File

@ -3222,10 +3222,6 @@ function wp_handle_comment_submission( $comment_data ) {
}
}
if ( '' == $comment_content ) {
return new WP_Error( 'require_valid_comment', __( '<strong>ERROR</strong>: 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', __( '<strong>ERROR</strong>: 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;