WP_HTML_Processor::expects_closer()publicWP 6.6.0

Indicates if the currently-matched node expects a closing token, or if it will self-close on the next step.

Most HTML elements expect a closer, such as a P element or a DIV element. Others, like an IMG element are void and don't have a closing tag. Special elements, such as SCRIPT and STYLE, are treated just like void tags. Text nodes and self-closing foreign content will also act just like a void tag, immediately closing as soon as the processor advances to the next token.

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

Хуков нет.

Возвращает

true|false|null. Whether to expect a closer for the currently-matched node, or null if not matched on any token.

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

$WP_HTML_Processor = new WP_HTML_Processor();
$WP_HTML_Processor->expects_closer( ?WP_HTML_Token $node ): ?bool;
?WP_HTML_Token $node **
-
По умолчанию: null

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

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

Код WP_HTML_Processor::expects_closer() WP 6.8.1

public function expects_closer( ?WP_HTML_Token $node = null ): ?bool {
	$token_name = $node->node_name ?? $this->get_token_name();

	if ( ! isset( $token_name ) ) {
		return null;
	}

	$token_namespace        = $node->namespace ?? $this->get_namespace();
	$token_has_self_closing = $node->has_self_closing_flag ?? $this->has_self_closing_flag();

	return ! (
		// Comments, text nodes, and other atomic tokens.
		'#' === $token_name[0] ||
		// Doctype declarations.
		'html' === $token_name ||
		// Void elements.
		( 'html' === $token_namespace && self::is_void( $token_name ) ) ||
		// Special atomic elements.
		( 'html' === $token_namespace && in_array( $token_name, array( 'IFRAME', 'NOEMBED', 'NOFRAMES', 'SCRIPT', 'STYLE', 'TEXTAREA', 'TITLE', 'XMP' ), true ) ) ||
		// Self-closing elements in foreign content.
		( 'html' !== $token_namespace && $token_has_self_closing )
	);
}