Make WordPress Core

Changeset 42661


Ignore:
Timestamp:
02/07/2018 08:08:47 PM (9 years ago)
Author:
boonebgorges
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/comment.php

    r42343 r42661  
    32233223        }
    32243224
    3225         if ( '' == $comment_content ) {
    3226                 return new WP_Error( 'require_valid_comment', __( '<strong>ERROR</strong>: please type a comment.' ), 200 );
    3227         }
    3228 
    32293225        $commentdata = compact(
    32303226                'comment_post_ID',
     
    32383234        );
    32393235
     3236        /**
     3237         * Filters whether an empty comment should be allowed.
     3238         *
     3239         * @since 5.0.0
     3240         *
     3241         * @param bool  $allow_empty_comment Default false.
     3242         * @param array $commentdata         Array of comment data to be sent to wp_insert_comment().
     3243         */
     3244        $allow_empty_comment = apply_filters( 'allow_empty_comment', false, $commentdata );
     3245        if ( '' === $comment_content && ! $allow_empty_comment ) {
     3246                return new WP_Error( 'require_valid_comment', __( '<strong>ERROR</strong>: please type a comment.' ), 200 );
     3247        }
     3248
    32403249        $check_max_lengths = wp_check_comment_data_max_lengths( $commentdata );
    32413250        if ( is_wp_error( $check_max_lengths ) ) {
Note: See TracChangeset for help on using the changeset viewer.