| 1 |
<?php |
| 2 |
/** |
| 3 |
* Process wp-class directive attribute. |
| 4 |
* |
| 5 |
* @package Gutenberg |
| 6 |
* @subpackage Interactivity API |
| 7 |
*/ |
| 8 |
|
| 9 |
/** |
| 10 |
* Process wp-class directive attribute. |
| 11 |
* |
| 12 |
* @param WP_Directive_Processor $tags Tags. |
| 13 |
* @param WP_Directive_Context $context Directive context. |
| 14 |
*/ |
| 15 |
function gutenberg_interactivity_process_wp_class( $tags, $context ) { |
| 16 |
if ( $tags->is_tag_closer() ) { |
| 17 |
return; |
| 18 |
} |
| 19 |
|
| 20 |
$prefixed_attributes = $tags->get_attribute_names_with_prefix( 'data-wp-class--' ); |
| 21 |
|
| 22 |
foreach ( $prefixed_attributes as $attr ) { |
| 23 |
list( , $class_name ) = WP_Directive_Processor::parse_attribute_name( $attr ); |
| 24 |
if ( empty( $class_name ) ) { |
| 25 |
continue; |
| 26 |
} |
| 27 |
|
| 28 |
$expr = $tags->get_attribute( $attr ); |
| 29 |
$add_class = gutenberg_interactivity_evaluate_reference( $expr, $context->get_context() ); |
| 30 |
if ( $add_class ) { |
| 31 |
$tags->add_class( $class_name ); |
| 32 |
} else { |
| 33 |
$tags->remove_class( $class_name ); |
| 34 |
} |
| 35 |
} |
| 36 |
} |
| 37 |
|