WP_REST_Comments_Controller::check_is_comment_content_allowedprotectedWP 5.6.0

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

Метод класса: WP_REST_Comments_Controller{}

Хуки из метода

Возвращает

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

Использование

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->check_is_comment_content_allowed( $prepared_comment );
$prepared_comment(массив) (обязательный)
The prepared comment data.

Список изменений

С версии 5.6.0 Введена.

Код WP_REST_Comments_Controller::check_is_comment_content_allowed() WP 6.9

protected function check_is_comment_content_allowed( $prepared_comment ) {
	if ( ! isset( $prepared_comment['comment_content'] ) ) {
		return true;
	}

	$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;
	}

	// Allow empty notes only when resolution metadata is valid.
	if (
		isset( $check['comment_type'] ) &&
		'note' === $check['comment_type'] &&
		isset( $check['meta']['_wp_note_status'] ) &&
		in_array( $check['meta']['_wp_note_status'], array( 'resolved', 'reopen' ), true )
	) {
		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'];
}