PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3
Jetpack – WP Security, Backup, Speed, & Growth v16.3
16.3 16.3-beta 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 All 508 releases
← All changes | jetpack_vendor/automattic/jetpack-blaze/src/class-dashboard-config-data.php +59 -14 12.5.2 → 16.3 View file →
@@ -7,9 +7,11 @@
7 7
8 8 namespace Automattic\Jetpack\Blaze;
9 9
10 10 use Automattic\Jetpack\Connection\Manager;
11 +use Automattic\Jetpack\Constants;
11 12 use Automattic\Jetpack\Current_Plan;
13 +use Automattic\Jetpack\Status\Host;
12 14 use Jetpack_Options;
13 15
14 16 /**
15 17 * Class Dashboard_Config_Data
@@ -14,9 +16,35 @@
14 16 /**
15 17 * Class Dashboard_Config_Data
16 18 */
17 19 class Dashboard_Config_Data {
20 +
18 21 /**
22 + * Blaze dashboard admin page. Default is admin.php.
23 + *
24 + * @var string
25 + */
26 + private $admin_page;
27 +
28 + /**
29 + * Blaze dashboard menu slug. Default is 'advertising'.
30 + *
31 + * @var string
32 + */
33 + private $menu_slug;
34 +
35 + /**
36 + * Dashboard config constructor.
37 + *
38 + * @param string $admin_page Dashboard admin page. Default is admin.php.
39 + * @param string $menu_slug Dashboard menu slug. Default is 'advertising'.
40 + */
41 + public function __construct( $admin_page = 'admin.php', $menu_slug = 'advertising' ) {
42 + $this->admin_page = $admin_page;
43 + $this->menu_slug = $menu_slug;
44 + }
45 +
46 + /**
19 47 * Set configData to window.configData.
20 48 *
21 49 * @param array $config_data The config data.
22 50 */
@@ -21,9 +49,10 @@
21 49 * @param array $config_data The config data.
22 50 */
23 51 public function get_js_config_data( $config_data = null ) {
24 52 return 'window.configData = ' . wp_json_encode(
25 - $config_data === null ? $this->get_data() : $config_data
53 + $config_data === null ? $this->get_data() : $config_data,
54 + JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP
26 55 ) . ';';
27 56 }
28 57
29 58 /**
@@ -30,13 +59,14 @@
30 59 * Return the config for the app.
31 60 */
32 61 public function get_data() {
33 62 $blog_id = Jetpack_Options::get_option( 'id' );
63 + $host = new Host();
34 64 $empty_object = json_decode( '{}' );
35 65
36 66 $user = $this->get_connected_user_identity();
37 67
38 - return array(
68 + $data = array(
39 69 'admin_page_base' => $this->get_admin_path(),
40 70 'api_root' => esc_url_raw( rest_url() ),
41 71 'blog_id' => $blog_id,
42 72 'enable_all_sections' => false,
@@ -49,10 +79,12 @@
49 79 'nonce' => wp_create_nonce( 'wp_rest' ),
50 80 'site_name' => \get_bloginfo( 'name' ),
51 81 'sections' => array(),
52 82 // Features are inlined in Calypso Blaze app (wp-calypso/apps/blaze-dashboard)
53 - 'features' => array(),
54 - 'intial_state' => array(
83 + 'features' => array(
84 + 'is_running_in_jetpack_site' => ! $host->is_wpcom_simple(),
85 + ),
86 + 'initial_state' => array(
55 87 'currentUser' => array(
56 88 'id' => $user['ID'],
57 89 'user' => $user,
58 90 'capabilities' => array(
@@ -63,16 +95,19 @@
63 95 'items' => array(
64 96 "$blog_id" => array(
65 97 'ID' => $blog_id,
66 98 'URL' => site_url(),
67 - 'jetpack' => true,
99 + 'jetpack' => ! $host->is_wpcom_simple(),
68 100 'visible' => true,
69 101 'capabilities' => $empty_object,
70 102 'products' => array(),
71 103 'plan' => $empty_object, // we need this empty object, otherwise the front end would crash on insight page.
72 104 'options' => array(
73 - 'admin_url' => admin_url(),
74 - 'gmt_offset' => $this->get_gmt_offset(),
105 + 'admin_url' => admin_url(),
106 + 'gmt_offset' => $this->get_gmt_offset(),
107 + 'is_wpcom_atomic' => $host->is_woa_site(),
108 + 'is_wpcom_simple' => $host->is_wpcom_simple(),
109 + 'jetpack_version' => Constants::get_constant( 'JETPACK__VERSION' ),
75 110 ),
76 111 ),
77 112 ),
78 113 'features' => array( "$blog_id" => array( 'data' => $this->get_plan_features() ) ),
@@ -78,8 +113,17 @@
78 113 'features' => array( "$blog_id" => array( 'data' => $this->get_plan_features() ) ),
79 114 ),
80 115 ),
81 116 );
117 +
118 + /**
119 + * Filter to allow modification of the Blaze dashboard config data.
120 + *
121 + * @param bool $data Blaze dashboard config data.
122 + *
123 + * @since 0.21.0
124 + */
125 + return apply_filters( 'jetpack_blaze_dashboard_config_data', $data );
82 126 }
83 127
84 128 /**
85 129 * Gets the WordPress.com user's identity, if connected.
@@ -91,9 +135,9 @@
91 135 if ( ! $user_data ) {
92 136 return array(
93 137 'ID' => 1000,
94 138 'username' => 'no-user',
95 - 'localeSlug' => $this->get_site_locale(),
139 + 'localeSlug' => $this->get_locale(),
96 140 'site_count' => 1,
97 141 );
98 142 }
99 143
@@ -100,9 +144,9 @@
100 144 return array(
101 145 'ID' => $user_data['ID'],
102 146 'username' => $user_data['login'],
103 147 'email' => $user_data['email'],
104 - 'localeSlug' => $this->get_site_locale(),
148 + 'localeSlug' => $this->get_locale(),
105 149 'site_count' => 1,
106 150 );
107 151 }
108 152
@@ -118,11 +162,12 @@
118 162 /**
119 163 * Page base for the Calypso admin page.
120 164 */
121 165 protected function get_admin_path() {
122 - // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
123 166 if ( ! isset( $_SERVER['PHP_SELF'] ) || ! isset( $_SERVER['QUERY_STRING'] ) ) {
124 - $parsed = wp_parse_url( admin_url( 'tools.php?page=advertising' ) );
167 + $admin_path = $this->admin_page . '?page=' . $this->menu_slug;
168 + $parsed = wp_parse_url( admin_url( $admin_path ) );
169 +
125 170 return $parsed['path'] . '?' . $parsed['query'];
126 171 }
127 172 // We do this because page.js requires the exactly page base to be set otherwise it will not work properly.
128 173 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
@@ -129,17 +174,17 @@
129 174 return wp_unslash( $_SERVER['PHP_SELF'] ) . '?' . wp_unslash( $_SERVER['QUERY_STRING'] );
130 175 }
131 176
132 177 /**
133 - * Get locale acceptable by Calypso.
178 + * Get the user's locale acceptable by Calypso.
134 179 */
135 - protected function get_site_locale() {
180 + protected function get_locale() {
136 181 /**
137 182 * In WP, locales are formatted as LANGUAGE_REGION, for example `en`, `en_US`, `es_AR`,
138 183 * but Calypso expects language-region, e.g. `en-us`, `en`, `es-ar`. So we need to convert
139 184 * them to lower case and replace the underscore with a dash.
140 185 */
141 - $locale = strtolower( get_locale() );
186 + $locale = strtolower( get_user_locale() );
142 187 $locale = str_replace( '_', '-', $locale );
143 188
144 189 return $locale;
145 190 }