WP_HTML_Open_Elements::current_node_is( string $identity ): bool

This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only by core. It is listed here for completeness.

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

Description

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' );

See also

Parameters

$identitystringrequired
Check if the current node has this name or type (depending on what is provided).

Return

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

Source

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

Changelog

VersionDescription
6.7.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.