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.
Built from https://develop.svn.wordpress.org/trunk@42661


git-svn-id: http://core.svn.wordpress.org/trunk@42490 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Boone Gorges 2018-02-07 20:09:30 +00:00
parent 39ce01d83a
commit 6c11ac0c16
2 changed files with 14 additions and 5 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;

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.0-alpha-42660';
$wp_version = '5.0-alpha-42661';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.