wppaste
WordPress

WP_HTML_Open_Elements

Since
6.4.0
Source
wp-includes/html-api/class-wp-html-open-elements.php:31
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

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 the

Changelog

Introduced in 6.4.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 7.0.4 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.