WP_Interactivity_API::data_wp_style_processor
Processes the data-wp-style directive.
It updates the style attribute value of the current HTML element based on the evaluation of its associated references.
Метод класса: WP_Interactivity_API{}
Хуков нет.
Возвращает
null. Ничего (null).
Использование
// private - только в коде основоного (родительского) класса $result = $this->data_wp_style_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_style_processor() WP Interactivity API::data wp style processor WP 6.9.1
private function data_wp_style_processor( WP_Interactivity_API_Directives_Processor $p, string $mode ) {
if ( 'enter' === $mode ) {
$entries = $this->get_directive_entries( $p, 'style' );
foreach ( $entries as $entry ) {
$style_property = $entry['suffix'];
if ( empty( $style_property ) || null !== $entry['unique_id'] ) {
continue;
}
$style_property_value = $this->evaluate( $entry );
$style_attribute_value = $p->get_attribute( 'style' );
$style_attribute_value = ( $style_attribute_value && ! is_bool( $style_attribute_value ) ) ? $style_attribute_value : '';
/*
* Checks first if the style property is not falsy and the style
* attribute value is not empty because if it is, it doesn't need to
* update the attribute value.
*/
if ( $style_property_value || $style_attribute_value ) {
$style_attribute_value = $this->merge_style_property( $style_attribute_value, $style_property, $style_property_value );
/*
* If the style attribute value is not empty, it sets it. Otherwise,
* it removes it.
*/
if ( ! empty( $style_attribute_value ) ) {
$p->set_attribute( 'style', $style_attribute_value );
} else {
$p->remove_attribute( 'style' );
}
}
}
}
}