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 +56 -27 12.5.2 → 16.3-a.1 View file →
@@ -1,6 +1,7 @@
1 1 <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
2 2
3 +use Automattic\Jetpack\Admin_UI\Admin_Menu;
3 4 use Automattic\Jetpack\Assets\Logo;
4 5 use Automattic\Jetpack\Connection\Initial_State as Connection_Initial_State;
5 6 use Automattic\Jetpack\Connection\Manager as Connection_Manager;
6 7 use Automattic\Jetpack\Status;
@@ -31,9 +32,11 @@
31 32 *
32 33 * @return string|false Return value from WordPress's `add_menu_page()`.
33 34 */
34 35 public function get_page_hook() {
35 - $icon = ( new Logo() )->get_base64_logo();
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();
36 39 return add_menu_page( 'Jetpack', 'Jetpack', 'jetpack_admin_page', 'jetpack', array( $this, 'render' ), $icon, 3 );
37 40 }
38 41
39 42 /**
@@ -45,9 +48,18 @@
45 48 public function add_page_actions( $hook ) {
46 49 /** This action is documented in class.jetpack-admin.php */
47 50 do_action( 'jetpack_admin_menu', $hook );
48 51
49 - 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 + }
50 62 return; // No need to handle the fallback redirection if we are not on the Jetpack page.
51 63 }
52 64
53 65 // Adding a redirect meta tag if the REST API is disabled.
@@ -68,17 +80,23 @@
68 80 }
69 81 }
70 82
71 83 /**
72 - * 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.
73 87 *
74 - * Works in Dev Mode or when user is connected.
75 - *
76 - * @since 4.3.0
88 + * @since 13.8
77 89 */
78 - public function jetpack_add_dashboard_sub_nav_item() {
79 - if ( ( new Status() )->is_offline_mode() || Jetpack::is_connection_ready() ) {
80 - add_submenu_page( 'jetpack', __( 'Dashboard', 'jetpack' ), __( 'Dashboard', 'jetpack' ), 'jetpack_admin_page', 'jetpack#/dashboard', '__return_null', 1 );
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() ) {
81 99 remove_submenu_page( 'jetpack', 'jetpack' );
82 100 }
83 101 }
84 102
@@ -137,9 +155,12 @@
137 155 * If those modules are not available, bail.
138 156 */
139 157 if (
140 158 ! Jetpack::is_module_active( 'post-by-email' )
141 - && ! Jetpack::is_module_active( 'publicize' )
159 + && (
160 + ! Jetpack::is_module_active( 'publicize' ) ||
161 + ! current_user_can( 'publish_posts' )
162 + )
142 163 ) {
143 164 return false;
144 165 }
145 166 }
@@ -150,14 +171,27 @@
150 171
151 172 /**
152 173 * Jetpack Settings sub-link.
153 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 + *
154 180 * @since 4.3.0
155 181 * @since 9.7.0 If Connection does not have an owner, restrict it to admins
156 182 */
157 183 public function jetpack_add_settings_sub_nav_item() {
158 184 if ( $this->can_access_settings() ) {
159 - 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 + );
160 194 }
161 195 }
162 196
163 197 /**
@@ -180,21 +214,8 @@
180 214 echo '</noscript>';
181 215 }
182 216
183 217 /**
184 - * Custom menu order.
185 - *
186 - * @deprecated since 9.2.0
187 - * @param array $menu_order Menu order.
188 - * @return array
189 - */
190 - public function jetpack_menu_order( $menu_order ) {
191 - _deprecated_function( __METHOD__, 'jetpack-9.2' );
192 -
193 - return $menu_order;
194 - }
195 -
196 - /**
197 218 * Add action to render page specific HTML.
198 219 *
199 220 * @return void
200 221 */
@@ -241,9 +262,9 @@
241 262 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
242 263 $target = sanitize_text_field( wp_unslash( $_GET['jp-react-redirect'] ) );
243 264 if ( isset( $allowed_paths[ $target ] ) ) {
244 265 wp_safe_redirect( $allowed_paths[ $target ] );
245 - exit;
266 + exit( 0 );
246 267 }
247 268 }
248 269
249 270 /**
@@ -272,8 +293,16 @@
272 293 $script_dependencies = $asset_manifest['dependencies'];
273 294 $version = $asset_manifest['version'];
274 295 }
275 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 +
276 305 wp_enqueue_script(
277 306 'react-plugin',
278 307 plugins_url( '_inc/build/admin.js', JETPACK__PLUGIN_FILE ),
279 308 $script_dependencies,
@@ -289,12 +318,12 @@
289 318 wp_set_script_translations( 'react-plugin', 'jetpack' );
290 319
291 320 // Add objects to be passed to the initial state of the app.
292 321 // Use wp_add_inline_script instead of wp_localize_script, see https://core.trac.wordpress.org/ticket/25280.
293 - 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' );
294 323
295 324 // This will set the default URL of the jp_redirects lib.
296 - 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' );
297 326
298 327 // Adds Connection package initial state.
299 328 Connection_Initial_State::render_script( 'react-plugin' );
300 329 }