PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-a.7
Jetpack – WP Security, Backup, Speed, & Growth v16.3-a.7
16.3-a.5 16.3-a.7 16.3-a.3 16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 All 506 releases
jetpack / jetpack_vendor / automattic / jetpack-scan-page / src / class-initial-state.php

class-initial-state.php in Jetpack – WP Security, Backup, Speed, & Growth 16.3-a.7, at jetpack_vendor/automattic/jetpack-scan-page/src/class-initial-state.php

70 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * The Scan React initial state.
4 *
5 * @package automattic/jetpack-scan-page
6 */
7
8 namespace Automattic\Jetpack\Scan_Page;
9
10 use Automattic\Jetpack\Status;
11 use Jetpack_Options;
12 use function admin_url;
13 use function esc_url_raw;
14 use function get_bloginfo;
15 use function get_locale;
16 use function get_option;
17 use function get_site_url;
18 use function plugins_url;
19 use function rest_url;
20 use function wp_create_nonce;
21 use function wp_json_encode;
22 use function wp_parse_url;
23
24 /**
25 * The Scan React initial state.
26 */
27 class Initial_State {
28 /**
29 * Get the initial state data.
30 *
31 * @return array
32 */
33 private function get_data() {
34 $gmt_offset = get_option( 'gmt_offset' );
35 $timezone_string = get_option( 'timezone_string' );
36 $home_host = wp_parse_url( get_site_url(), PHP_URL_HOST );
37
38 return array(
39 'API' => array(
40 'WP_API_root' => esc_url_raw( rest_url() ),
41 'WP_API_nonce' => wp_create_nonce( 'wp_rest' ),
42 ),
43 'jetpackStatus' => array(
44 'calypsoSlug' => ( new Status() )->get_site_suffix(),
45 ),
46 'siteData' => array(
47 'id' => Jetpack_Options::get_option( 'id' ),
48 'title' => get_bloginfo( 'name' ) ? get_bloginfo( 'name' ) : get_site_url(),
49 'adminUrl' => esc_url_raw( admin_url() ),
50 'slug' => is_string( $home_host ) ? $home_host : '',
51 'gmtOffset' => is_numeric( $gmt_offset ) ? (float) $gmt_offset : 0.0,
52 'timezoneString' => is_string( $timezone_string ) ? $timezone_string : '',
53 'locale' => str_replace( '_', '-', (string) get_locale() ),
54 ),
55 'assets' => array(
56 'buildUrl' => plugins_url( '../build/', __FILE__ ),
57 ),
58 );
59 }
60
61 /**
62 * Render the initial state into a JavaScript variable.
63 *
64 * @return string
65 */
66 public function render() {
67 return 'var JPSCAN_INITIAL_STATE=' . wp_json_encode( $this->get_data(), JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP ) . ';';
68 }
69 }
70