summaryrefslogtreecommitdiffstats
path: root/wp-includes/html-api/class-wp-html-open-elements.php
diff options
context:
space:
mode:
Diffstat (limited to 'wp-includes/html-api/class-wp-html-open-elements.php')
-rw-r--r--wp-includes/html-api/class-wp-html-open-elements.php81
1 files changed, 80 insertions, 1 deletions
diff --git a/wp-includes/html-api/class-wp-html-open-elements.php b/wp-includes/html-api/class-wp-html-open-elements.php
index 1234abc..1547980 100644
--- a/wp-includes/html-api/class-wp-html-open-elements.php
+++ b/wp-includes/html-api/class-wp-html-open-elements.php
@@ -52,6 +52,56 @@ class WP_HTML_Open_Elements {
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
+ */
+ 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
+ */
+ 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 ) {
+ $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 ) {
+ $this->push_handler = $handler;
+ }
+
+ /**
* Reports if a specific node is in the stack of open elements.
*
* @since 6.4.0
@@ -258,11 +308,15 @@ class WP_HTML_Open_Elements {
*/
public function pop() {
$item = array_pop( $this->stack );
-
if ( null === $item ) {
return false;
}
+ if ( 'context-node' === $item->bookmark_name ) {
+ $this->stack[] = $item;
+ return false;
+ }
+
$this->after_element_pop( $item );
return true;
}
@@ -279,6 +333,10 @@ class WP_HTML_Open_Elements {
*/
public function pop_until( $tag_name ) {
foreach ( $this->walk_up() as $item ) {
+ if ( 'context-node' === $item->bookmark_name ) {
+ return true;
+ }
+
$this->pop();
if (
@@ -319,6 +377,10 @@ class WP_HTML_Open_Elements {
* @return bool Whether the node was found and removed from the stack of open elements.
*/
public function remove_node( $token ) {
+ if ( 'context-node' === $token->bookmark_name ) {
+ return false;
+ }
+
foreach ( $this->walk_up() as $position_from_end => $item ) {
if ( $token->bookmark_name !== $item->bookmark_name ) {
continue;
@@ -429,6 +491,10 @@ class WP_HTML_Open_Elements {
$this->has_p_in_button_scope = true;
break;
}
+
+ if ( null !== $this->push_handler ) {
+ ( $this->push_handler )( $item );
+ }
}
/**
@@ -458,5 +524,18 @@ class WP_HTML_Open_Elements {
$this->has_p_in_button_scope = $this->has_element_in_button_scope( 'P' );
break;
}
+
+ if ( null !== $this->pop_handler ) {
+ ( $this->pop_handler )( $item );
+ }
+ }
+
+ /**
+ * Wakeup magic method.
+ *
+ * @since 6.6.0
+ */
+ public function __wakeup() {
+ throw new \LogicException( __CLASS__ . ' should never be unserialized' );
}
}