WP_HTML_Processor::get_token_type()
Indicates the kind of matched token, if any.
This differs from get_token_name() in that it always returns a static string indicating the type, whereas get_token_name() may return values derived from the token itself, such as a tag name or processing instruction tag.
Possible values:
- #tag when matched on a tag.
- #text when matched on a text node.
- #cdata-section when matched on a CDATA node.
- #comment when matched on a comment.
- #doctype when matched on a DOCTYPE declaration.
- #presumptuous-tag when matched on an empty tag closer.
- #funky-comment when matched on a funky comment.
Method of the class: WP_HTML_Processor{}
No Hooks.
Return
String|null
. What kind of token is matched, or null.
Usage
$WP_HTML_Processor = new WP_HTML_Processor(); $WP_HTML_Processor->get_token_type();
Changelog
Since 6.6.0 | Introduced. |
Since 6.6.0 | Subclassed for the HTML Processor. |
WP_HTML_Processor::get_token_type() WP HTML Processor::get token type code WP 6.6.2
public function get_token_type() { if ( $this->is_virtual() ) { /* * This logic comes from the Tag Processor. * * @todo It would be ideal not to repeat this here, but it's not clearly * better to allow passing a token name to `get_token_type()`. */ $node_name = $this->current_element->token->node_name; $starting_char = $node_name[0]; if ( 'A' <= $starting_char && 'Z' >= $starting_char ) { return '#tag'; } if ( 'html' === $node_name ) { return '#doctype'; } return $node_name; } return parent::get_token_type(); }