| 1 |
<?php |
| 2 |
/** |
| 3 |
* Process wp-context directive attribute. |
| 4 |
* |
| 5 |
* @package wp-directives |
| 6 |
*/ |
| 7 |
|
| 8 |
/** |
| 9 |
* Process wp-context directive attribute. |
| 10 |
* |
| 11 |
* @param WP_Directive_Processor $tags Tags. |
| 12 |
* @param WP_Directive_Context $context Directive context. |
| 13 |
*/ |
| 14 |
function gutenberg_interactivity_process_wp_context( $tags, $context ) { |
| 15 |
if ( $tags->is_tag_closer() ) { |
| 16 |
$context->rewind_context(); |
| 17 |
return; |
| 18 |
} |
| 19 |
|
| 20 |
$value = $tags->get_attribute( 'data-wp-context' ); |
| 21 |
|
| 22 |
$new_context = json_decode( |
| 23 |
is_string( $value ) && ! empty( $value ) ? $value : '{}', |
| 24 |
true |
| 25 |
); |
| 26 |
|
| 27 |
$context->set_context( $new_context ?? array() ); |
| 28 |
} |
| 29 |
|