WP_HTML_Tag_Processor::add_classpublicWP 6.2.0

Adds a new class name to the currently matched tag.

Метод класса: WP_HTML_Tag_Processor{}

Хуков нет.

Возвращает

true|false. Whether the class was set to be added.

Использование

$WP_HTML_Tag_Processor = new WP_HTML_Tag_Processor();
$WP_HTML_Tag_Processor->add_class( $class_name ): bool;
$class_name(строка) (обязательный)
The class name to add.

Список изменений

С версии 6.2.0 Введена.

Код WP_HTML_Tag_Processor::add_class() WP 7.0.4

public function add_class( $class_name ): bool {
	if (
		self::STATE_MATCHED_TAG !== $this->parser_state ||
		$this->is_closing_tag
	) {
		return false;
	}

	if ( self::QUIRKS_MODE !== $this->compat_mode ) {
		$this->classname_updates[ $class_name ] = self::ADD_CLASS;
		return true;
	}

	/*
	 * Because class names are matched ASCII-case-insensitively in quirks mode,
	 * this needs to see if a case variant of the given class name is already
	 * enqueued and update that existing entry, if so. This picks the casing of
	 * the first-provided class name for all lexical variations.
	 */
	$class_name_length = strlen( $class_name );
	foreach ( $this->classname_updates as $updated_name => $action ) {
		if (
			strlen( $updated_name ) === $class_name_length &&
			0 === substr_compare( $updated_name, $class_name, 0, $class_name_length, true )
		) {
			$this->classname_updates[ $updated_name ] = self::ADD_CLASS;
			return true;
		}
	}

	$this->classname_updates[ $class_name ] = self::ADD_CLASS;
	return true;
}