WP_REST_Comments_Controller::check_is_comment_content_allowed()protectedWP 5.6.0

If empty comments are not allowed, checks if the provided comment content is not empty.

Method of the class: WP_REST_Comments_Controller{}

Hooks from the method

Return

true|false. True if the content is allowed, false otherwise.

Usage

// protected - for code of main (parent) or child class
$result = $this->check_is_comment_content_allowed( $prepared_comment );
$prepared_comment(array) (required)
The prepared comment data.

Changelog

Since 5.6.0 Introduced.

WP_REST_Comments_Controller::check_is_comment_content_allowed() code WP 6.6.2

protected function check_is_comment_content_allowed( $prepared_comment ) {
	$check = wp_parse_args(
		$prepared_comment,
		array(
			'comment_post_ID'      => 0,
			'comment_author'       => null,
			'comment_author_email' => null,
			'comment_author_url'   => null,
			'comment_parent'       => 0,
			'user_id'              => 0,
		)
	);

	/** This filter is documented in wp-includes/comment.php */
	$allow_empty = apply_filters( 'allow_empty_comment', false, $check );

	if ( $allow_empty ) {
		return true;
	}

	/*
	 * Do not allow a comment to be created with missing or empty
	 * comment_content. See wp_handle_comment_submission().
	 */
	return '' !== $check['comment_content'];
}