File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed
Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -635,6 +635,44 @@ public function get_unsupported_exception() {
635635 return $ this ->unsupported_exception ;
636636 }
637637
638+ /**
639+ * Use a selector to advance.
640+ *
641+ * @param string $selectors
642+ * @return Generator<void>|null
643+ */
644+ public function select_all ( string $ selectors ): ?Generator {
645+ $ select = WP_CSS_Selector_List::from_selectors ( $ selectors );
646+ if ( null === $ select ) {
647+ return null ;
648+ }
649+
650+ while ( $ this ->next_tag () ) {
651+ if ( $ select ->matches ( $ this ) ) {
652+ yield ;
653+ }
654+ }
655+ }
656+
657+ /**
658+ * Select the next matching element.
659+ *
660+ * If iterating through matching elements, use `select_all` instead.
661+ *
662+ * @param string $selectors
663+ * @return bool|null
664+ */
665+ public function select ( string $ selectors ) {
666+ $ selection = $ this ->select_all ( $ selectors );
667+ if ( null === $ selection ) {
668+ return null ;
669+ }
670+ foreach ( $ selection as $ _ ) {
671+ return true ;
672+ }
673+ return false ;
674+ }
675+
638676 /**
639677 * Finds the next tag matching the $query.
640678 *
You can’t perform that action at this time.
0 commit comments