WP_Interactivity_API::data_wp_class_processor()privateWP 6.5.0

Processes the data-wp-class directive.

It adds or removes CSS classes in the current HTML element based on the evaluation of its associated references.

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

Хуков нет.

Возвращает

null. Ничего (null).

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

// private - только в коде основоного (родительского) класса
$result = $this->data_wp_class_processor( $p, $mode );
$p(WP_Interactivity_API_Directives_Processor) (обязательный)
The directives processor instance.
$mode(строка) (обязательный)
Whether the processing is entering or exiting the tag.

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

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

Код WP_Interactivity_API::data_wp_class_processor() WP 6.7.1

private function data_wp_class_processor( WP_Interactivity_API_Directives_Processor $p, string $mode ) {
	if ( 'enter' === $mode ) {
		$all_class_directives = $p->get_attribute_names_with_prefix( 'data-wp-class--' );

		foreach ( $all_class_directives as $attribute_name ) {
			list( , $class_name ) = $this->extract_prefix_and_suffix( $attribute_name );
			if ( empty( $class_name ) ) {
				return;
			}

			$attribute_value = $p->get_attribute( $attribute_name );
			$result          = $this->evaluate( $attribute_value );

			if ( $result ) {
				$p->add_class( $class_name );
			} else {
				$p->remove_class( $class_name );
			}
		}
	}
}