Skip to content

Commit b30cfcb

Browse files
committed
Implement has_class
1 parent cd912f9 commit b30cfcb

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

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

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4669,13 +4669,38 @@ public function remove_class( $class_name ): bool {
46694669
/**
46704670
* Returns if a matched tag contains the given ASCII case-insensitive class name.
46714671
*
4672+
*
4673+
* > When matching against a document which is in quirks mode, class names must be matched
4674+
* > ASCII case-insensitively; class selectors are otherwise case-sensitive, only matching
4675+
* > class names they are identical to.
4676+
*
4677+
* @see https://www.w3.org/TR/selectors-4/#class-html
4678+
*
46724679
* @since 6.6.0 Subclassed for the HTML Processor.
4680+
* @since 6.7.0 Matches are case sensitive in no-quirks mode (the default).
46734681
*
46744682
* @param string $wanted_class Look for this CSS class name, ASCII case-insensitive.
46754683
* @return bool|null Whether the matched tag contains the given class name, or null if not matched.
46764684
*/
46774685
public function has_class( $wanted_class ): ?bool {
4678-
return $this->is_virtual() ? null : parent::has_class( $wanted_class );
4686+
if ( $this->is_virtual() ) {
4687+
return false;
4688+
}
4689+
4690+
if ( self::STATE_MATCHED_TAG !== $this->parser_state ) {
4691+
return null;
4692+
}
4693+
4694+
$compare_func = WP_HTML_Processor_State::QUIRKS_MODE === $this->state->compat_mode ?
4695+
'strcasecmp' :
4696+
'strcmp';
4697+
4698+
foreach ( $this->class_list() as $class_name ) {
4699+
if ( 0 === $compare_func( $class_name, $wanted_class ) ) {
4700+
return true;
4701+
}
4702+
}
4703+
return false;
46794704
}
46804705

46814706
/**

0 commit comments

Comments
 (0)