Skip to content

Commit

Permalink
HTML Processor implement select methods
Browse files Browse the repository at this point in the history
  • Loading branch information
sirreal committed Nov 28, 2024
1 parent cdd9389 commit 732ae24
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion src/wp-includes/html-api/class-wp-html-processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,36 @@ public function get_unsupported_exception() {
* @param string $selectors
* @return Generator<void>|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;
}

/**
Expand Down

0 comments on commit 732ae24

Please sign in to comment.