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 +47 -13 13.6.216.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 /**
@@ -228,9 +262,9 @@
228 262 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
229 263 $target = sanitize_text_field( wp_unslash( $_GET['jp-react-redirect'] ) );
230 264 if ( isset( $allowed_paths[ $target ] ) ) {
231 265 wp_safe_redirect( $allowed_paths[ $target ] );
232 - exit;
266 + exit( 0 );
233 267 }
234 268 }
235 269
236 270 /**
@@ -284,9 +318,9 @@
284 318 wp_set_script_translations( 'react-plugin', 'jetpack' );
285 319
286 320 // Add objects to be passed to the initial state of the app.
287 321 // Use wp_add_inline_script instead of wp_localize_script, see https://core.trac.wordpress.org/ticket/25280.
288 - 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' );
289 323
290 324 // This will set the default URL of the jp_redirects lib.
291 325 wp_add_inline_script( 'react-plugin', 'var jetpack_redirects = { currentSiteRawUrl: "' . $site_suffix . '"' . $blog_id_prop . ' };', 'before' );
292 326