PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-a.1
Jetpack – WP Security, Backup, Speed, & Growth v16.3-a.1
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 13.9.2 14.0.1 All 504 releases
← All changes | _inc/lib/admin-pages/class.jetpack-react-page.php +60 -28 12.0.3 → 16.3-a.1 View file →
@@ -1,5 +1,8 @@
1 1 <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
2 +
3 +use Automattic\Jetpack\Admin_UI\Admin_Menu;
4 +use Automattic\Jetpack\Assets\Logo;
2 5 use Automattic\Jetpack\Connection\Initial_State as Connection_Initial_State;
3 6 use Automattic\Jetpack\Connection\Manager as Connection_Manager;
4 7 use Automattic\Jetpack\Status;
5 8
@@ -29,9 +32,12 @@
29 32 *
30 33 * @return string|false Return value from WordPress's `add_menu_page()`.
31 34 */
32 35 public function get_page_hook() {
33 - return add_menu_page( 'Jetpack', 'Jetpack', 'jetpack_admin_page', 'jetpack', array( $this, 'render' ), 'div', 3 );
36 + $logo = new Logo();
37 + // Keep this fallback in sync with Jetpack_Network::add_network_admin_menu().
38 + $icon = method_exists( $logo, 'get_base64_admin_menu_logo' ) ? $logo->get_base64_admin_menu_logo() : $logo->get_base64_logo();
39 + return add_menu_page( 'Jetpack', 'Jetpack', 'jetpack_admin_page', 'jetpack', array( $this, 'render' ), $icon, 3 );
34 40 }
35 41
36 42 /**
37 43 * Add page action.
@@ -42,9 +48,18 @@
42 48 public function add_page_actions( $hook ) {
43 49 /** This action is documented in class.jetpack-admin.php */
44 50 do_action( 'jetpack_admin_menu', $hook );
45 51
46 - if ( ! isset( $_GET['page'] ) || 'jetpack' !== $_GET['page'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- This is view logic.
52 + if ( ! isset( $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
53 + return;
54 + }
55 + $page = sanitize_text_field( wp_unslash( $_GET['page'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
56 + if ( 'jetpack' !== $page ) {
57 + if ( strpos( $page, 'jetpack/' ) === 0 ) {
58 + $section = substr( $page, 8 );
59 + wp_safe_redirect( admin_url( 'admin.php?page=jetpack#/' . $section ) );
60 + exit( 0 );
61 + }
47 62 return; // No need to handle the fallback redirection if we are not on the Jetpack page.
48 63 }
49 64
50 65 // Adding a redirect meta tag if the REST API is disabled.
@@ -65,17 +80,23 @@
65 80 }
66 81 }
67 82
68 83 /**
69 - * Add Jetpack Dashboard sub-link and point it to AAG if the user can view stats, manage modules or if Protect is active.
84 + * Remove the main Jetpack submenu if a site is in offline mode or connected
85 + * or if My Jetpack is available.
86 + * At that point, admins can access the Jetpack Dashboard instead.
70 87 *
71 - * Works in Dev Mode or when user is connected.
72 - *
73 - * @since 4.3.0
88 + * @since 13.8
74 89 */
75 - public function jetpack_add_dashboard_sub_nav_item() {
76 - if ( ( new Status() )->is_offline_mode() || Jetpack::is_connection_ready() ) {
77 - add_submenu_page( 'jetpack', __( 'Dashboard', 'jetpack' ), __( 'Dashboard', 'jetpack' ), 'jetpack_admin_page', 'jetpack#/dashboard', '__return_null' );
90 + public function remove_jetpack_menu() {
91 + $is_offline_mode = ( new Status() )->is_offline_mode();
92 + $has_my_jetpack = (
93 + class_exists( 'Automattic\Jetpack\My_Jetpack\Initializer' ) &&
94 + method_exists( 'Automattic\Jetpack\My_Jetpack\Initializer', 'should_initialize' ) &&
95 + \Automattic\Jetpack\My_Jetpack\Initializer::should_initialize()
96 + );
97 +
98 + if ( $is_offline_mode || $has_my_jetpack || Jetpack::is_connection_ready() ) {
78 99 remove_submenu_page( 'jetpack', 'jetpack' );
79 100 }
80 101 }
81 102
@@ -134,9 +155,12 @@
134 155 * If those modules are not available, bail.
135 156 */
136 157 if (
137 158 ! Jetpack::is_module_active( 'post-by-email' )
138 - && ! Jetpack::is_module_active( 'publicize' )
159 + && (
160 + ! Jetpack::is_module_active( 'publicize' ) ||
161 + ! current_user_can( 'publish_posts' )
162 + )
139 163 ) {
140 164 return false;
141 165 }
142 166 }
@@ -147,14 +171,27 @@
147 171
148 172 /**
149 173 * Jetpack Settings sub-link.
150 174 *
175 + * Shares the bottom tier with Beta Tester so it lands below the alphabetical run
176 + * rather than inside it; the two sort by title within the tier. The upsell still
177 + * renders underneath — Admin_Menu appends that one after sorting, so it never
178 + * competes on position.
179 + *
151 180 * @since 4.3.0
152 181 * @since 9.7.0 If Connection does not have an owner, restrict it to admins
153 182 */
154 183 public function jetpack_add_settings_sub_nav_item() {
155 184 if ( $this->can_access_settings() ) {
156 - add_submenu_page( 'jetpack', __( 'Settings', 'jetpack' ), __( 'Settings', 'jetpack' ), 'jetpack_admin_page', 'jetpack#/settings', '__return_null' );
185 + Admin_Menu::add_menu(
186 + __( 'Settings', 'jetpack' ),
187 + __( 'Settings', 'jetpack' ),
188 + 'jetpack_admin_page',
189 + Jetpack::admin_url( array( 'page' => 'jetpack#/settings' ) ),
190 + null,
191 + Admin_Menu::POSITION_LAST,
192 + array( 'key' => 'jetpack-settings' )
193 + );
157 194 }
158 195 }
159 196
160 197 /**
@@ -177,21 +214,8 @@
177 214 echo '</noscript>';
178 215 }
179 216
180 217 /**
181 - * Custom menu order.
182 - *
183 - * @deprecated since 9.2.0
184 - * @param array $menu_order Menu order.
185 - * @return array
186 - */
187 - public function jetpack_menu_order( $menu_order ) {
188 - _deprecated_function( __METHOD__, 'jetpack-9.2' );
189 -
190 - return $menu_order;
191 - }
192 -
193 - /**
194 218 * Add action to render page specific HTML.
195 219 *
196 220 * @return void
197 221 */
@@ -238,9 +262,9 @@
238 262 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
239 263 $target = sanitize_text_field( wp_unslash( $_GET['jp-react-redirect'] ) );
240 264 if ( isset( $allowed_paths[ $target ] ) ) {
241 265 wp_safe_redirect( $allowed_paths[ $target ] );
242 - exit;
266 + exit( 0 );
243 267 }
244 268 }
245 269
246 270 /**
@@ -269,8 +293,16 @@
269 293 $script_dependencies = $asset_manifest['dependencies'];
270 294 $version = $asset_manifest['version'];
271 295 }
272 296
297 + $blog_id_prop = '';
298 + if ( ! defined( 'IS_WPCOM' ) || ! IS_WPCOM ) {
299 + $blog_id = Connection_Manager::get_site_id( true );
300 + if ( $blog_id ) {
301 + $blog_id_prop = ', currentBlogID: "' . (int) $blog_id . '"';
302 + }
303 + }
304 +
273 305 wp_enqueue_script(
274 306 'react-plugin',
275 307 plugins_url( '_inc/build/admin.js', JETPACK__PLUGIN_FILE ),
276 308 $script_dependencies,
@@ -286,13 +318,13 @@
286 318 wp_set_script_translations( 'react-plugin', 'jetpack' );
287 319
288 320 // Add objects to be passed to the initial state of the app.
289 321 // Use wp_add_inline_script instead of wp_localize_script, see https://core.trac.wordpress.org/ticket/25280.
290 - wp_add_inline_script( 'react-plugin', 'var Initial_State=JSON.parse(decodeURIComponent("' . rawurlencode( wp_json_encode( Jetpack_Redux_State_Helper::get_initial_state() ) ) . '"));', 'before' );
322 + wp_add_inline_script( 'react-plugin', 'var Initial_State=' . wp_json_encode( Jetpack_Redux_State_Helper::get_initial_state(), JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP ) . ';', 'before' );
291 323
292 324 // This will set the default URL of the jp_redirects lib.
293 - wp_add_inline_script( 'react-plugin', 'var jetpack_redirects = { currentSiteRawUrl: "' . $site_suffix . '" };', 'before' );
325 + wp_add_inline_script( 'react-plugin', 'var jetpack_redirects = { currentSiteRawUrl: "' . $site_suffix . '"' . $blog_id_prop . ' };', 'before' );
294 326
295 327 // Adds Connection package initial state.
296 - wp_add_inline_script( 'react-plugin', Connection_Initial_State::render(), 'before' );
328 + Connection_Initial_State::render_script( 'react-plugin' );
297 329 }
298 330 }