Skip to content

Commit

Permalink
Add and use matches_tag type selector method
Browse files Browse the repository at this point in the history
  • Loading branch information
sirreal committed Dec 9, 2024
1 parent 3949cc5 commit c696889
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/wp-includes/html-api/class-wp-css-complex-selector.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ private function explore_matches( array $selectors, array $breadcrumbs ): bool {

switch ( $combinator ) {
case self::COMBINATOR_CHILD:
if ( '*' === $selector->type_selector->ident || strcasecmp( $breadcrumbs[0], $selector->type_selector->ident ) === 0 ) {
if ( $selector->type_selector->matches_tag( $breadcrumbs[0] ) ) {
return $this->explore_matches( array_slice( $selectors, 2 ), array_slice( $breadcrumbs, 1 ) );
}
return false;

case self::COMBINATOR_DESCENDANT:
// Find _all_ the breadcrumbs that match and recurse from each of them.
for ( $i = 0; $i < count( $breadcrumbs ); $i++ ) {
if ( '*' === $selector->type_selector->ident || strcasecmp( $breadcrumbs[ $i ], $selector->type_selector->ident ) === 0 ) {
if ( $selector->type_selector->matches_tag( $breadcrumbs[ $i ] ) ) {
$next_crumbs = array_slice( $breadcrumbs, $i + 1 );
if ( $this->explore_matches( array_slice( $selectors, 2 ), $next_crumbs ) ) {
return true;
Expand Down
8 changes: 8 additions & 0 deletions src/wp-includes/html-api/class-wp-css-type-selector.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ public function matches( WP_HTML_Tag_Processor $processor ): bool {
if ( null === $tag_name ) {
return false;
}
return $this->matches_tag( $tag_name );
}

/**
* @param string $tag_name
* @return bool
*/
public function matches_tag( string $tag_name ): bool {
if ( '*' === $this->ident ) {
return true;
}
Expand Down

0 comments on commit c696889

Please sign in to comment.