| 1 |
<?php |
| 2 |
/** |
| 3 |
* The React initial state. |
| 4 |
* |
| 5 |
* @package automattic/jetpack-backup-plugin |
| 6 |
*/ |
| 7 |
|
| 8 |
use Automattic\Jetpack\Connection\Plugin_Storage as Connection_Plugin_Storage; |
| 9 |
use Automattic\Jetpack\Status; |
| 10 |
|
| 11 |
/** |
| 12 |
* The React initial state. |
| 13 |
*/ |
| 14 |
class Initial_State { |
| 15 |
/** |
| 16 |
* Get the initial state data. |
| 17 |
* |
| 18 |
* @return array |
| 19 |
*/ |
| 20 |
private function get_data() { |
| 21 |
return array( |
| 22 |
'API' => array( |
| 23 |
'WP_API_root' => esc_url_raw( rest_url() ), |
| 24 |
'WP_API_nonce' => wp_create_nonce( 'wp_rest' ), |
| 25 |
'registrationNonce' => wp_create_nonce( 'jetpack-registration-nonce' ), |
| 26 |
), |
| 27 |
'jetpackStatus' => array( |
| 28 |
'calypsoSlug' => ( new Status() )->get_site_suffix(), |
| 29 |
), |
| 30 |
'connectedPlugins' => Connection_Plugin_Storage::get_all(), |
| 31 |
'siteData' => array( |
| 32 |
'id' => \Jetpack_Options::get_option( 'id' ), |
| 33 |
), |
| 34 |
'assets' => array( |
| 35 |
'buildUrl' => plugins_url( 'build/', JETPACK_BACKUP_PLUGIN_ROOT_FILE ), |
| 36 |
), |
| 37 |
); |
| 38 |
} |
| 39 |
|
| 40 |
/** |
| 41 |
* Render the initial state into a JavaScript variable. |
| 42 |
* |
| 43 |
* @return string |
| 44 |
*/ |
| 45 |
public function render() { |
| 46 |
add_action( 'jetpack_use_iframe_authorization_flow', '__return_true' ); |
| 47 |
|
| 48 |
return 'var JPBACKUP_INITIAL_STATE=JSON.parse(decodeURIComponent("' . rawurlencode( wp_json_encode( $this->get_data() ) ) . '"));'; |
| 49 |
} |
| 50 |
|
| 51 |
} |
| 52 |
|