| 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 |
* @param string $ns Namespace. |
| 14 |
*/ |
| 15 |
function gutenberg_interactivity_process_wp_context( $tags, $context, $ns ) { |
| 16 |
if ( $tags->is_tag_closer() ) { |
| 17 |
$context->rewind_context(); |
| 18 |
return; |
| 19 |
} |
| 20 |
|
| 21 |
$attr_value = $tags->get_attribute( 'data-wp-context' ); |
| 22 |
|
| 23 |
//Separate namespace and value from the context directive attribute. |
| 24 |
list( $ns, $data ) = is_string( $attr_value ) && ! empty( $attr_value ) |
| 25 |
? WP_Directive_Processor::parse_attribute_value( $attr_value, $ns ) |
| 26 |
: array( $ns, null ); |
| 27 |
|
| 28 |
// Add parsed data to the context under the corresponding namespace. |
| 29 |
$context->set_context( array( $ns => is_array( $data ) ? $data : array() ) ); |
| 30 |
} |
| 31 |
|