WP_HTML_Open_Elements
- Since
- 6.4.0
- Source
wp-includes/html-api/class-wp-html-open-elements.php:30
Core class used by the HTML processor during HTML parsing for managing the stack of open elements.
Description
This class is designed for internal use by the HTML processor.
Initially, the stack of open elements is empty. The stack grows downwards; the topmost node on the stack is the first one added to the stack, and the bottommost node of the stack is the most recently added node in the stack (notwithstanding when the stack is manipulated in a random access fashion as part of the handling for misnested tags).
Compatibility
- WordPress
- since 6.4.0
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0).
Properties · 4
$stackWP_HTML_Token[]public- Holds the stack of open element references.
$has_p_in_button_scopeboolprivate- Whether a P element is in button scope currently.
$pop_handlerClosure|nullprivate- A function that will be called when an item is popped off the stack of open elements.
$push_handlerClosure|nullprivate- A function that will be called when an item is pushed onto the stack of open elements.
Methods · 27
- set_pop_handler()Sets a pop handler that will be called when an item is popped off the stack of open elements.
- set_push_handler()Sets a push handler that will be called when an item is pushed onto the stack of open elements.
- at()Returns the name of the node at the nth position on the stack of open elements, or `null` if no such position exists.
- contains()Reports if a node of a given name is in the stack of open elements.
- contains_node()Reports if a specific node is in the stack of open elements.
- count()Returns how many nodes are currently in the stack of open elements.
- current_node()Returns the node at the end of the stack of open elements, if one exists. If the stack is empty, returns null.
- current_node_is()Indicates if the current node is of a given type or name.
- has_element_in_specific_scope()Returns whether an element is in a specific scope.
- has_element_in_scope()Returns whether a particular element is in scope.
- has_element_in_list_item_scope()Returns whether a particular element is in list item scope.
- has_element_in_button_scope()Returns whether a particular element is in button scope.
- has_element_in_table_scope()Returns whether a particular element is in table scope.
- has_element_in_select_scope()Returns whether a particular element is in select scope.
- has_p_in_button_scope()Returns whether a P is in BUTTON scope.
- pop()Pops a node off of the stack of open elements.
- pop_until()Pops nodes off of the stack of open elements until an HTML tag with the given name has been popped.
- push()Pushes a node onto the stack of open elements.
- remove_node()Removes a specific node from the stack of open elements.
- walk_down()Steps through the stack of open elements, starting with the top element (added first) and walking downwards to the one added last.
- walk_up()Steps through the stack of open elements, starting with the bottom element (added last) and walking upwards to the one added first.
- after_element_push()Updates internal flags after adding an element.
- after_element_pop()Updates internal flags after removing an element.
- clear_to_table_context()Clear the stack back to a table context.
- clear_to_table_body_context()Clear the stack back to a table body context.
- clear_to_table_row_context()Clear the stack back to a table row context.
- __wakeup()Wakeup magic method.
Source code
class WP_HTML_Open_Elements { /** * Holds the stack of open element references. * * @since 6.4.0 * * @var WP_HTML_Token[] */ public $stack = array(); /** * Whether a P element is in button scope currently. * * This class optimizes scope lookup by pre-calculating * this value when elements are added and removed to the * stack of open elements which might change its value. * This avoids frequent iteration over the stack. * * @since 6.4.0 * * @var bool */ private $has_p_in_button_scope = false; /** * A function that will be called when an item is popped off the stack of open elements. * * The function will be called with the popped item as its argument. * * @since 6.6.0 * * @var Closure|null */ private $pop_handler = null; /** * A function that will be called when an item is pushed onto the stack of open elements. * * The function will be called with the pushed item as its argument. * * @since 6.6.0 * * @var Closure|null */ private $push_handler = null; /** * Sets a pop handler that will be called when an item is popped off the stack of * open elements. * * The function will be called with the pushed item as its argument. * * @since 6.6.0 * * @param Closure $handler The handler function. */ public function set_pop_handler( Closure $handler ): void { $this->pop_handler = $handler; } /** * Sets a push handler that will be called when an item is pushed onto the stack of * open elements. * * The function will be called with the pushed item as its argument. * * @since 6.6.0 * * @param Closure $handler The handler function. */ public function set_push_handler( Closure $handler ): void { $this->push_handler = $handler; } /** * Returns the name of the node at the nth position on the stack * of open elements, or `null` if no such position exists. * * Note that this uses a 1-based index, which represents the * "nth item" on the stack, counting from the top, where theChangelog
Introduced in 6.4.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.7.7 tag, from
src/wp-includes/html-api/class-wp-html-open-elements.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.