PluginProbe
Jetpack VaultPress Backup / 1.2.0
Jetpack VaultPress Backup v1.2.0
3.0 3.1 3.2 3.3 3.4 3.5 3.6 3.7.1 3.8 3.9 trunk 0.2.0 1.0.0 1.0.1 1.1.0 1.2.0 1.3.0 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.5 1.6 1.7 All 37 releases
jetpack-backup / src / php / class-initial-state.php

class-initial-state.php in Jetpack VaultPress Backup 1.2.0, at src/php/class-initial-state.php

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