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