| 1 |
<?php |
| 2 |
/** |
| 3 |
* Process the wp-interactive directive. |
| 4 |
* |
| 5 |
* @package Gutenberg |
| 6 |
* @subpackage Interactivity API |
| 7 |
*/ |
| 8 |
|
| 9 |
/** |
| 10 |
* Process wp-interactive directive. |
| 11 |
* |
| 12 |
* @param WP_Directive_Processor $tags Tags. |
| 13 |
* @param WP_Directive_Context $context Directive context. |
| 14 |
* @param string $ns Namespace. |
| 15 |
* @param array $ns_stack Namespace stack. |
| 16 |
*/ |
| 17 |
function gutenberg_interactivity_process_wp_interactive( $tags, $context, $ns, &$ns_stack ) { |
| 18 |
// Pop the current namespace if this is the closing tag of an island. |
| 19 |
if ( $tags->is_tag_closer() ) { |
| 20 |
array_pop( $ns_stack ); |
| 21 |
return; |
| 22 |
} |
| 23 |
|
| 24 |
/* |
| 25 |
* Decode the data-wp-interactive attribute. In the case it is not a valid |
| 26 |
* JSON string, NULL is stored in `$island_data`. |
| 27 |
*/ |
| 28 |
$island = $tags->get_attribute( 'data-wp-interactive' ); |
| 29 |
$island_data = is_string( $island ) && ! empty( $island ) |
| 30 |
? json_decode( $island, true ) |
| 31 |
: null; |
| 32 |
|
| 33 |
/* |
| 34 |
* Push the newly defined namespace, or the current one if the island |
| 35 |
* definition was invalid or does not contain a namespace. |
| 36 |
* |
| 37 |
* This is done because the function pops out the current namespace from the |
| 38 |
* stack whenever it finds an island's closing tag, independently of whether |
| 39 |
* the island definition was correct or it contained a valid namespace. |
| 40 |
*/ |
| 41 |
$ns_stack[] = isset( $island_data ) && $island_data['namespace'] |
| 42 |
? $island_data['namespace'] |
| 43 |
: $ns; |
| 44 |
} |
| 45 |
|