| 1 |
<?php |
| 2 |
/** |
| 3 |
* Functions to expose the store of the WP_Interactivity_Initial_State class. |
| 4 |
* |
| 5 |
* @package Gutenberg |
| 6 |
* @subpackage Interactivity API |
| 7 |
*/ |
| 8 |
|
| 9 |
if ( ! function_exists( 'wp_initial_state' ) ) { |
| 10 |
/** |
| 11 |
* Merge data into the state with the given namespace. |
| 12 |
* |
| 13 |
* @param string $store_ns Namespace. |
| 14 |
* @param array $data State to merge. |
| 15 |
* |
| 16 |
* @return array The current state for the given namespace. |
| 17 |
*/ |
| 18 |
function wp_initial_state( $store_ns, $data = null ) { |
| 19 |
if ( $data ) { |
| 20 |
WP_Interactivity_Initial_State::merge_state( $store_ns, $data ); |
| 21 |
} |
| 22 |
return WP_Interactivity_Initial_State::get_state( $store_ns ); |
| 23 |
} |
| 24 |
|
| 25 |
/** |
| 26 |
* Render the Interactivity API initial state in the frontend. |
| 27 |
*/ |
| 28 |
add_action( 'wp_footer', array( 'WP_Interactivity_Initial_State', 'render' ), 8 ); |
| 29 |
} |
| 30 |
|