diff --git a/wp-includes/html-api/class-wp-html-processor.php b/wp-includes/html-api/class-wp-html-processor.php
index 3b2efce1c9..e3100abc69 100644
--- a/wp-includes/html-api/class-wp-html-processor.php
+++ b/wp-includes/html-api/class-wp-html-processor.php
@@ -623,6 +623,35 @@ class WP_HTML_Processor extends WP_HTML_Tag_Processor {
return $breadcrumbs;
}
+ /**
+ * Returns the nesting depth of the current location in the document.
+ *
+ * Example:
+ *
+ * $processor = WP_HTML_Processor::create_fragment( '
' );
+ * // The processor starts in the BODY context, meaning it has depth from the start: HTML > BODY.
+ * 2 === $processor->get_current_depth();
+ *
+ * // Opening the DIV element increases the depth.
+ * $processor->next_token();
+ * 3 === $processor->get_current_depth();
+ *
+ * // Opening the P element increases the depth.
+ * $processor->next_token();
+ * 4 === $processor->get_current_depth();
+ *
+ * // The P element is closed during `next_token()` so the depth is decreased to reflect that.
+ * $processor->next_token();
+ * 3 === $processor->get_current_depth();
+ *
+ * @since 6.6.0
+ *
+ * @return int Nesting-depth of current location in the document.
+ */
+ public function get_current_depth() {
+ return $this->state->stack_of_open_elements->count();
+ }
+
/**
* Parses next element in the 'in body' insertion mode.
*
diff --git a/wp-includes/version.php b/wp-includes/version.php
index 35cb8ebfd9..1cfc031679 100644
--- a/wp-includes/version.php
+++ b/wp-includes/version.php
@@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
-$wp_version = '6.6-alpha-58190';
+$wp_version = '6.6-alpha-58191';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.