PluginProbe
Gutenberg / 17.5.0
Gutenberg v17.5.0
24.0.0 23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 12.6.0 All 403 releases
gutenberg / lib / experimental / interactivity-api / directives / wp-interactive.php

wp-interactive.php in Gutenberg 17.5.0, at lib/experimental/interactivity-api/directives/wp-interactive.php

45 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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