diff --git a/src/wp-includes/html-api/class-wp-html-processor.php b/src/wp-includes/html-api/class-wp-html-processor.php
index 1a6dcfcc9b817..438dee4c47f4e 100644
--- a/src/wp-includes/html-api/class-wp-html-processor.php
+++ b/src/wp-includes/html-api/class-wp-html-processor.php
@@ -641,7 +641,36 @@ public function get_unsupported_exception() {
* @param string $selectors
* @return Generator|null
*/
- public function select( string $selectors ): ?Generator {
+ public function select_all( string $selectors ): ?Generator {
+ $select = WP_CSS_Selector_List::from_selectors( $selectors );
+ if ( null === $select ) {
+ return null;
+ }
+
+ while ( $this->next_tag() ) {
+ if ( $select->matches( $this ) ) {
+ yield;
+ }
+ }
+ }
+
+ /**
+ * Select the next matching element.
+ *
+ * If iterating through matching elements, use `select_all` instead.
+ *
+ * @param string $selectors
+ * @return bool|null
+ */
+ public function select( string $selectors ) {
+ $selection = $this->select_all( $selectors );
+ if ( null === $selection ) {
+ return null;
+ }
+ foreach ( $selection as $_ ) {
+ return true;
+ }
+ return false;
}
/**