PluginProbe
Jetpack VaultPress Backup / 0.2.0
Jetpack VaultPress Backup v0.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 0.2.0, at src/php/class-initial-state.php

71 lines 1.7 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\Constants;
9 use Automattic\Jetpack\Device_Detection\User_Agent_Info;
10 use Automattic\Jetpack\Status;
11
12 /**
13 * The React initial state.
14 */
15 class Initial_State {
16 /**
17 * Get the initial state data.
18 *
19 * @return array
20 */
21 private function get_data() {
22 return array(
23 'API' => array(
24 'WP_API_root' => esc_url_raw( rest_url() ),
25 'WP_API_nonce' => wp_create_nonce( 'wp_rest' ),
26 'registrationNonce' => wp_create_nonce( 'jetpack-registration-nonce' ),
27 ),
28 'jetpackStatus' => array(
29 'calypsoSlug' => ( new Status() )->get_site_suffix(),
30 ),
31 );
32 }
33
34 /**
35 * Whether we can the connection iframe.
36 *
37 * @return bool
38 */
39 private function can_use_connection_iframe() {
40 global $is_safari;
41
42 /**
43 * Filters whether the connection manager should use the iframe authorization
44 * flow instead of the regular redirect-based flow.
45 *
46 * @since 8.3.0
47 *
48 * @param Boolean $is_iframe_flow_used should the iframe flow be used, defaults to false.
49 */
50 $iframe_flow = apply_filters( 'jetpack_use_iframe_authorization_flow', false );
51
52 if ( ! $iframe_flow ) {
53 return false;
54 }
55
56 return ! $is_safari && ! User_Agent_Info::is_opera_desktop() && ! Constants::is_true( 'JETPACK_SHOULD_NOT_USE_CONNECTION_IFRAME' );
57 }
58
59 /**
60 * Render the initial state into a JavaScript variable.
61 *
62 * @return string
63 */
64 public function render() {
65 add_action( 'jetpack_use_iframe_authorization_flow', '__return_true' );
66
67 return 'var JPBACKUP_INITIAL_STATE=JSON.parse(decodeURIComponent("' . rawurlencode( wp_json_encode( $this->get_data() ) ) . '"));';
68 }
69
70 }
71