WP_HTML_Open_Elements::current_node_is │ public │ WP 6.7.0

Indicates if the current node is of a given type or name.

It's possible to pass either a node type or a node name to this function. In the case there is no current element it will always return false.

Example:

// Is the current node a text node?
$stack->current_node_is( '#text' );
// Is the current node a DIV element?
$stack->current_node_is( 'DIV' );
// Is the current node any element/tag?
$stack->current_node_is( '#tag' );

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

Внутренняя функция — эта функция рассчитана на использование самим ядром. Не рекомендуется использовать эту функцию в своем коде.

Хуков нет.

Возвращает

bool. Whether there is a current element that matches the given identity, whether a token name or type.

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

$WP_HTML_Open_Elements = new WP_HTML_Open_Elements();
$WP_HTML_Open_Elements->current_node_is( $identity ): bool;
$identity(строка) (обязательный)
Check if the current node has this name or type (depending on what is provided).

Заметки

Смотрите: WP_HTML_Tag_Processor::get_token_type
Смотрите: WP_HTML_Tag_Processor::get_token_name

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

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

Код WP_HTML_Open_Elements::current_node_is() WP 7.1.3

public function current_node_is( string $identity ): bool {
	$current_node = end( $this->stack );
	if ( false === $current_node ) {
		return false;
	}

	$current_node_name = $current_node->node_name;

	return (
		$current_node_name === $identity ||
		( '#doctype' === $identity && 'html' === $current_node_name ) ||
		( '#tag' === $identity && ctype_upper( $current_node_name ) )
	);
}