Skip to content

Commit ed8f34f

Browse files
committed
Implement has_class
1 parent 5267774 commit ed8f34f

1 file changed

Lines changed: 26 additions & 1 deletion

File tree

src/wp-includes/html-api/class-wp-html-processor.php

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4645,13 +4645,38 @@ public function remove_class( $class_name ): bool {
46454645
/**
46464646
* Returns if a matched tag contains the given ASCII case-insensitive class name.
46474647
*
4648+
*
4649+
* > When matching against a document which is in quirks mode, class names must be matched
4650+
* > ASCII case-insensitively; class selectors are otherwise case-sensitive, only matching
4651+
* > class names they are identical to.
4652+
*
4653+
* @see https://www.w3.org/TR/selectors-4/#class-html
4654+
*
46484655
* @since 6.6.0 Subclassed for the HTML Processor.
4656+
* @since 6.7.0 Matches are case sensitive in no-quirks mode (the default).
46494657
*
46504658
* @param string $wanted_class Look for this CSS class name, ASCII case-insensitive.
46514659
* @return bool|null Whether the matched tag contains the given class name, or null if not matched.
46524660
*/
46534661
public function has_class( $wanted_class ): ?bool {
4654-
return $this->is_virtual() ? null : parent::has_class( $wanted_class );
4662+
if ( $this->is_virtual() ) {
4663+
return false;
4664+
}
4665+
4666+
if ( self::STATE_MATCHED_TAG !== $this->parser_state ) {
4667+
return null;
4668+
}
4669+
4670+
$compare_func = WP_HTML_Processor_State::QUIRKS_MODE === $this->state->compat_mode ?
4671+
'strcasecmp' :
4672+
'strcmp';
4673+
4674+
foreach ( $this->class_list() as $class_name ) {
4675+
if ( 0 === $compare_func( $class_name, $wanted_class ) ) {
4676+
return true;
4677+
}
4678+
}
4679+
return false;
46554680
}
46564681

46574682
/**

0 commit comments

Comments
 (0)