WP_HTML_Tag_Processor::has_class()
Returns if a matched tag contains the given ASCII case-insensitive class name.
Method of the class: WP_HTML_Tag_Processor{}
No Hooks.
Returns
true|false|null
. Whether the matched tag contains the given class name, or null if not matched.
Usage
$WP_HTML_Tag_Processor = new WP_HTML_Tag_Processor(); $WP_HTML_Tag_Processor->has_class( $wanted_class ): ?bool;
- $wanted_class(string) (required)
- Look for this CSS class name, ASCII case-insensitive.
Changelog
Since 6.4.0 | Introduced. |
WP_HTML_Tag_Processor::has_class() WP HTML Tag Processor::has class code WP 6.8.1
public function has_class( $wanted_class ): ?bool { if ( self::STATE_MATCHED_TAG !== $this->parser_state ) { return null; } $case_insensitive = self::QUIRKS_MODE === $this->compat_mode; $wanted_length = strlen( $wanted_class ); foreach ( $this->class_list() as $class_name ) { if ( strlen( $class_name ) === $wanted_length && 0 === substr_compare( $class_name, $wanted_class, 0, strlen( $wanted_class ), $case_insensitive ) ) { return true; } } return false; }