PluginProbe ʕ •ᴥ•ʔ
Jetpack – WP Security, Backup, Speed, & Growth / 13.1.5
Jetpack – WP Security, Backup, Speed, & Growth v13.1.5
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 14.1.1 14.2.2 14.3.1 14.4.2 14.5.1 14.6.1 14.7.1 14.8.1 14.9.2 15.0.3 15.1.2 15.2.1 15.3.2 15.4.1 15.5.1 15.6.1 15.7.2 15.8.1 15.9.2 16.0.2 16.1.3 16.2-a.5 16.2-a.3 16.1.2 16.2-a.1 16.1.1 16.1 16.1-beta 16.1-beta.2 16.1-beta.3 16.1-a.5 16.1-a.3 16.0.1 16.1-a.1 16.0 16.0-beta 16.0-a.7 16.0-a.5 15.9.1 16.0-a.3 16.0-a.1 15.9 15.9-beta 15.9-a.7 15.9-a.5 15.9-a.3 15.9-a.1 15.8 15.8-beta 15.8-a.7 15.8-a.5 5.2.5 5.3.4 5.4.4 5.5.5 5.6.5 5.7.5 5.8.4 5.9.4 6.0.4 6.1 6.1.1 6.1.2 6.1.3 6.1.4 6.1.5 6.2 6.2.1 6.2.2 6.2.3 6.2.4 6.2.5 6.3 6.3.1 6.3.2 6.3.3 6.3.4 6.3.5 6.3.6 6.3.7 6.4 6.4.1 6.4.2 6.4.3 6.4.4 6.4.5 6.4.6 6.5 6.5.1 6.5.2 6.5.3 6.5.4 6.6 6.6.1 6.6.2 6.6.3 6.6.4 6.6.5 6.7 6.7.1 6.7.2 6.7.3 6.7.4 6.8 6.8.1 6.8.2 6.8.3 6.8.4 6.8.5 6.9 6.9.1 6.9.2 6.9.3 6.9.4 7.0 7.0.1 7.0.2 7.0.3 7.0.4 7.0.5 7.1 7.1.1 7.1.2 7.1.3 7.1.4 7.1.5 7.2 7.2.1 7.2.1.1 7.2.2 7.2.3 7.2.4 7.2.5 7.3 7.3.0.1 7.3.1 7.3.1.1 7.3.2 7.3.3 7.3.4 7.3.5 7.4 7.4.1 7.4.2 7.4.3 7.4.4 7.4.5 7.5 7.5.0.1 7.5.1 7.5.2 7.5.3 7.5.4 7.5.5 7.5.6 7.5.7 7.6 7.6.1 7.6.2 7.6.3 7.6.4 7.7 7.7.1 7.7.2 7.7.3 7.7.4 7.7.5 7.7.6 7.8 7.8.1 7.8.2 7.8.3 7.8.4 7.9 7.9.1 7.9.2 7.9.3 7.9.4 8.0 8.0.1 8.0.2 8.0.3 8.1 8.1.1 8.1.2 8.1.3 8.1.4 8.2 8.2.0.1 8.2.1 8.2.2 8.2.3 8.2.4 8.2.5 8.2.6 8.3 8.3.1 8.3.2 8.3.3 8.4 8.4.1 8.4.2 8.4.3 8.4.4 8.4.5 8.5 8.5.1 8.5.2 8.5.3 8.6 8.6.1 8.6.2 8.6.3 8.6.4 8.7 8.7.0.1 8.7.1 8.7.2 8.7.3 8.7.4 8.8 8.8.1 8.8.2 8.8.3 8.8.4 8.8.5 8.9 8.9.1 8.9.2 8.9.3 8.9.4 9.0 9.0.1 9.0.2 9.0.3 9.0.4 9.0.5 9.1 9.1.1 9.1.2 9.1.3 9.2 9.2.1 9.2.2 9.2.3 9.2.4 9.3 9.3.1 9.3.2 9.3.3 9.3.4 9.3.5 9.4 9.4.1 9.4.2 9.4.3 9.4.4 9.5 9.5.1 9.5.2 9.5.3 9.5.4 9.5.5 9.6 9.6.1 9.6.2 9.6.3 9.6.4 9.7 9.7.1 9.7.2 15.7-beta.2 9.7.3 15.7.1 9.8 15.8-a.1 9.8.1 15.8-a.3 9.8.2 2.0.9 9.8.3 2.1.7 9.9 2.2.10 9.9.1 2.3.10 9.9.2 2.4.7 9.9.3 2.5.5 2.6.6 2.7.5 2.8.5 2.9.6 3.0.6 3.1.5 3.2.5 3.3.6 3.4.6 3.5.6 3.6.4 3.7.5 3.8.5 3.9.10 4.0.7 4.1.4 4.2.5 4.3.5 4.4.5 4.5.3 4.6.3 4.7.4 4.8.5 4.9.3 5.0.3 5.1.4 trunk 10.0 10.0.1 10.0.2 10.1 10.1.1 10.1.2 10.2 10.2.1 10.2.2 10.2.3 10.3 10.3.1 10.3.2 10.4 10.4.1 10.4.2 10.5 10.5.1 10.5.2 10.5.3 10.6 10.6.1 10.6.2 10.7 10.7.1 10.7.2 10.8 10.8.1 10.8.2 10.9 10.9.1 10.9.2 10.9.3 11.0 11.0.1 11.0.2 11.1 11.1.1 11.1.2 11.1.3 11.1.4 11.2 11.2.1 11.2.2 11.3 11.3.1 11.3.2 11.3.3 11.3.4 11.4 11.4.1 11.4.2 11.5 11.5.1 11.5.2 11.5.3 11.6 11.6.1 11.6.2 11.7 11.7.1 11.7.2 11.7.3 11.8 11.8.3 11.8.4 11.8.5 11.8.6 11.9 11.9.1 11.9.2 11.9.3 12.0 12.0.1 12.0.2 12.1 12.1.1 12.1.2 12.2 12.2.1 12.2.2 12.3 12.3.1 12.4 12.4.1 12.5 12.5.1 12.6 12.6.1 12.6.2 12.6.3 12.7 12.7.1 12.7.2 12.8 12.8.1 12.8.2 12.9 12.9.1 12.9.2 12.9.3 12.9.4 13.0 13.0.1 13.1 13.1.1 13.1.2 13.1.3 13.1.4 13.2 13.2.1 13.2.2 13.2.3 13.3 13.3.1 13.3.2 13.4 13.4.1 13.4.2 13.4.3 13.4.4 13.5 13.5.1 13.6 13.6.1 13.7 13.7.1 13.8 13.8.1 13.8.2 13.9 13.9.1 14.0 14.1 14.2 14.2.1 14.3 14.4 14.4.1 14.5 14.6 14.7 14.8 14.9 14.9.1 15.0 15.0.1 15.0.2 15.1 15.1.1 15.2 15.3 15.3.1 15.4 15.5 15.6 15.7 15.7-a.1 15.7-a.3 15.7-a.5 15.7-a.7 15.7-beta
jetpack / modules / masterbar / admin-menu / class-atomic-admin-menu.php
jetpack / modules / masterbar / admin-menu Last commit date
admin-menu-nav-unification-rtl.css 2 years ago admin-menu-nav-unification-rtl.min.css 2 years ago admin-menu-nav-unification.css 2 years ago admin-menu-nav-unification.min.css 2 years ago admin-menu-rtl.css 2 years ago admin-menu-rtl.min.css 2 years ago admin-menu.css 2 years ago admin-menu.js 2 years ago admin-menu.min.css 2 years ago class-admin-menu.php 2 years ago class-atomic-admin-menu.php 2 years ago class-base-admin-menu.php 2 years ago class-dashboard-switcher-tracking.php 3 years ago class-domain-only-admin-menu.php 2 years ago class-jetpack-admin-menu.php 2 years ago class-p2-admin-menu.php 4 years ago class-wpcom-admin-menu.php 2 years ago class-wpcom-email-subscription-checker.php 3 years ago dashicon-set.php 4 years ago globe-icon.svg 3 years ago load.php 2 years ago menu-mappings.php 3 years ago
class-atomic-admin-menu.php
582 lines
1 <?php
2 /**
3 * Atomic Admin Menu file.
4 *
5 * @package automattic/jetpack
6 */
7
8 namespace Automattic\Jetpack\Dashboard_Customizations;
9
10 use Automattic\Jetpack\Connection\Client;
11 use Automattic\Jetpack\Current_Plan as Jetpack_Plan;
12 use Automattic\Jetpack\Redirect;
13 use Automattic\Jetpack\Status;
14
15 require_once __DIR__ . '/class-admin-menu.php';
16
17 /**
18 * Class Atomic_Admin_Menu.
19 */
20 class Atomic_Admin_Menu extends Admin_Menu {
21
22 /**
23 * Atomic_Admin_Menu constructor.
24 */
25 protected function __construct() {
26 parent::__construct();
27
28 add_action( 'wp_enqueue_scripts', array( $this, 'dequeue_scripts' ), 20 );
29 add_action( 'admin_enqueue_scripts', array( $this, 'dequeue_scripts' ), 20 );
30 add_action( 'wp_ajax_sidebar_state', array( $this, 'ajax_sidebar_state' ) );
31 add_action( 'wp_ajax_jitm_dismiss', array( $this, 'wp_ajax_jitm_dismiss' ) );
32 add_action( 'wp_ajax_upsell_nudge_jitm', array( $this, 'wp_ajax_upsell_nudge_jitm' ) );
33
34 if ( ! $this->is_api_request ) {
35 add_filter( 'submenu_file', array( $this, 'override_the_theme_installer' ), 10, 2 );
36 }
37
38 add_action(
39 'admin_menu',
40 function () {
41 remove_action( 'admin_menu', 'gutenberg_menu', 9 );
42 },
43 0
44 );
45
46 // Add notices to the settings pages when there is a Calypso page available.
47 if ( get_option( 'wpcom_admin_interface' ) === 'wp-admin' ) {
48 add_action( 'current_screen', array( $this, 'add_settings_page_notice' ) );
49 }
50 }
51
52 /**
53 * Dequeues unnecessary scripts.
54 */
55 public function dequeue_scripts() {
56 wp_dequeue_script( 'a8c_wpcom_masterbar_overrides' ); // Initially loaded in modules/masterbar/masterbar/class-masterbar.php.
57 }
58
59 /**
60 * Determines whether the current locale is right-to-left (RTL).
61 *
62 * Performs the check against the current locale set on the WordPress.com's account settings.
63 * See `Masterbar::__construct` in `modules/masterbar/masterbar/class-masterbar.php`.
64 */
65 public function is_rtl() {
66 return get_user_option( 'jetpack_wpcom_is_rtl' );
67 }
68
69 /**
70 * Create the desired menu output.
71 */
72 public function reregister_menu_items() {
73 parent::reregister_menu_items();
74
75 $this->add_my_home_menu();
76 $this->remove_gutenberg_menu();
77
78 if ( ! get_option( 'wpcom_is_staging_site' ) ) {
79 $this->add_my_mailboxes_menu();
80 }
81
82 // Not needed outside of wp-admin.
83 if ( ! $this->is_api_request ) {
84 $this->add_browse_sites_link();
85 $this->add_site_card_menu();
86 $this->add_new_site_link();
87 }
88
89 $this->add_woocommerce_installation_menu();
90 ksort( $GLOBALS['menu'] );
91 }
92
93 /**
94 * Get the preferred view for the given screen.
95 *
96 * @param string $screen Screen identifier.
97 * @param bool $fallback_global_preference (Optional) Whether the global preference for all screens should be used
98 * as fallback if there is no specific preference for the given screen.
99 * Default: true.
100 * @return string
101 */
102 public function get_preferred_view( $screen, $fallback_global_preference = true ) {
103
104 // Export on Atomic sites are always managed on WP Admin.
105 if ( in_array( $screen, array( 'export.php' ), true ) ) {
106 return self::CLASSIC_VIEW;
107 }
108
109 /**
110 * When Jetpack SSO is disabled, we need to force Calypso because it might create confusion to be redirected to WP-Admin.
111 * Furthermore, because we don't display the quick switcher, users having an WP-Admin interface by default won't be able to go back to the Calyso version.
112 */
113 if ( ! \Jetpack::is_module_active( 'sso' ) ) {
114 return self::DEFAULT_VIEW;
115 }
116
117 return parent::get_preferred_view( $screen, $fallback_global_preference );
118 }
119
120 /**
121 * Adds Users menu.
122 */
123 public function add_users_menu() {
124 $slug = current_user_can( 'list_users' ) ? 'users.php' : 'profile.php';
125 if ( self::DEFAULT_VIEW === $this->get_preferred_view( 'users.php' ) ) {
126 $submenus_to_update = array(
127 'users.php' => 'https://wordpress.com/people/team/' . $this->domain,
128 );
129 $this->update_submenus( $slug, $submenus_to_update );
130 }
131
132 add_submenu_page( 'users.php', esc_attr__( 'Subscribers', 'jetpack' ), __( 'Subscribers', 'jetpack' ), 'list_users', 'https://wordpress.com/subscribers/' . $this->domain, null );
133
134 remove_submenu_page( 'users.php', 'profile.php' );
135 add_submenu_page( 'users.php', esc_attr__( 'My Profile', 'jetpack' ), __( 'My Profile', 'jetpack' ), 'read', 'https://wordpress.com/me/', null );
136
137 // Users who can't 'list_users' will see "Profile" menu & "Profile > Account Settings" as submenu.
138 add_submenu_page( $slug, esc_attr__( 'Account Settings', 'jetpack' ), __( 'Account Settings', 'jetpack' ), 'read', 'https://wordpress.com/me/account' );
139 }
140
141 /**
142 * Adds Plugins menu.
143 */
144 public function add_plugins_menu() {
145
146 global $submenu;
147
148 // Calypso plugins screens link.
149 $plugins_slug = 'https://wordpress.com/plugins/' . $this->domain;
150
151 // Link to the Marketplace from Plugins > Add New on Atomic sites where the wpcom_admin_interface option is set to wp-admin.
152 if ( self::CLASSIC_VIEW === $this->get_preferred_view( 'plugins.php' ) ) {
153 $submenus_to_update = array( 'plugin-install.php' => $plugins_slug );
154 $this->update_submenus( 'plugins.php', $submenus_to_update );
155 return;
156 }
157
158 // Link to the Marketplace on sites that can't manage plugins.
159 if (
160 function_exists( 'wpcom_site_has_feature' ) &&
161 ! wpcom_site_has_feature( \WPCOM_Features::MANAGE_PLUGINS )
162 ) {
163 add_menu_page( __( 'Plugins', 'jetpack' ), __( 'Plugins', 'jetpack' ), 'manage_options', $plugins_slug, null, 'dashicons-admin-plugins', '65' );
164 return;
165 }
166
167 if ( ! isset( $submenu['plugins.php'] ) ) {
168 return;
169 }
170
171 $plugins_submenu = $submenu['plugins.php'];
172
173 // Move "Add New" plugin submenu to the top position.
174 foreach ( $plugins_submenu as $submenu_key => $submenu_keys ) {
175 if ( 'plugin-install.php' === $submenu_keys[2] ) {
176 // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
177 $submenu['plugins.php'] = array( $submenu_key => $plugins_submenu[ $submenu_key ] ) + $plugins_submenu;
178 }
179 }
180
181 $submenus_to_update = array( 'plugin-install.php' => $plugins_slug );
182
183 $this->update_submenus( 'plugins.php', $submenus_to_update );
184 }
185
186 /**
187 * Adds the site switcher link if user has more than one site.
188 */
189 public function add_browse_sites_link() {
190 $site_count = get_user_option( 'wpcom_site_count' );
191 if ( ! $site_count || $site_count < 2 ) {
192 return;
193 }
194
195 // Unnecessary because "My Sites" always links to the Sites page.
196 if ( 'wp-admin' === get_option( 'wpcom_admin_interface' ) ) {
197 return;
198 }
199
200 // Add the menu item.
201 add_menu_page( __( 'site-switcher', 'jetpack' ), __( 'Browse sites', 'jetpack' ), 'read', 'https://wordpress.com/sites', null, 'dashicons-arrow-left-alt2', 0 );
202 add_filter( 'add_menu_classes', array( $this, 'set_browse_sites_link_class' ) );
203 }
204
205 /**
206 * Adds a custom element class for Site Switcher menu item.
207 *
208 * @param array $menu Associative array of administration menu items.
209 *
210 * @return array
211 */
212 public function set_browse_sites_link_class( array $menu ) {
213 foreach ( $menu as $key => $menu_item ) {
214 if ( 'site-switcher' !== $menu_item[3] ) {
215 continue;
216 }
217
218 $menu[ $key ][4] = add_cssclass( 'site-switcher', $menu_item[4] );
219 break;
220 }
221
222 return $menu;
223 }
224
225 /**
226 * Adds a link to the menu to create a new site.
227 */
228 public function add_new_site_link() {
229 $site_count = get_user_option( 'wpcom_site_count' );
230 if ( $site_count && $site_count > 1 ) {
231 return;
232 }
233
234 add_menu_page( __( 'Add New Site', 'jetpack' ), __( 'Add New Site', 'jetpack' ), 'read', 'https://wordpress.com/start?ref=calypso-sidebar', null, 'dashicons-plus-alt' );
235 }
236
237 /**
238 * Adds site card component.
239 */
240 public function add_site_card_menu() {
241 $default = plugins_url( 'globe-icon.svg', __FILE__ );
242 $icon = get_site_icon_url( 32, $default );
243 $blog_name = get_option( 'blogname' ) !== '' ? get_option( 'blogname' ) : $this->domain;
244 $is_coming_soon = ( new Status() )->is_coming_soon();
245
246 $badge = '';
247
248 if ( get_option( 'wpcom_is_staging_site' ) ) {
249 $badge .= '<span class="site__badge site__badge-staging">' . esc_html__( 'Staging', 'jetpack' ) . '</span>';
250 }
251
252 if ( ( function_exists( 'site_is_private' ) && site_is_private() ) || $is_coming_soon ) {
253 $badge .= sprintf(
254 '<span class="site__badge site__badge-private">%s</span>',
255 $is_coming_soon ? esc_html__( 'Coming Soon', 'jetpack' ) : esc_html__( 'Private', 'jetpack' )
256 );
257 }
258
259 $site_card = '
260 <div class="site__info">
261 <div class="site__title">%1$s</div>
262 <div class="site__domain">%2$s</div>
263 %3$s
264 </div>';
265
266 $site_card = sprintf(
267 $site_card,
268 $blog_name,
269 $this->domain,
270 $badge
271 );
272
273 add_menu_page( 'site-card', $site_card, 'read', get_home_url(), null, $icon, 1 );
274 add_filter( 'add_menu_classes', array( $this, 'set_site_card_menu_class' ) );
275 }
276
277 /**
278 * Adds a custom element class and id for Site Card's menu item.
279 *
280 * @param array $menu Associative array of administration menu items.
281 *
282 * @return array
283 */
284 public function set_site_card_menu_class( array $menu ) {
285 foreach ( $menu as $key => $menu_item ) {
286 if ( 'site-card' !== $menu_item[3] ) {
287 continue;
288 }
289
290 $classes = ' toplevel_page_site-card';
291
292 // webclip.png is the default on WoA sites. Anything other than that means we have a custom site icon.
293 if ( has_site_icon() && 'https://s0.wp.com/i/webclip.png' !== get_site_icon_url( 512 ) ) {
294 $classes .= ' has-site-icon';
295 }
296
297 $menu[ $key ][4] = $menu_item[4] . $classes;
298 $menu[ $key ][5] = 'toplevel_page_site_card';
299 break;
300 }
301
302 return $menu;
303 }
304
305 /**
306 * Returns the first available upsell nudge.
307 *
308 * @return array
309 */
310 public function get_upsell_nudge() {
311 $jitm = \Automattic\Jetpack\JITMS\JITM::get_instance();
312 $message_path = 'calypso:sites:sidebar_notice';
313 $message = $jitm->get_messages( $message_path, wp_json_encode( array( 'message_path' => $message_path ) ), false );
314
315 if ( isset( $message[0] ) ) {
316 $message = $message[0];
317 return array(
318 'content' => $message->content->message,
319 'cta' => $message->CTA->message, // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
320 'link' => $message->CTA->link, // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
321 'tracks_impression_event_name' => $message->tracks->display->name,
322 'tracks_impression_cta_name' => $message->tracks->display->props->cta_name,
323 'tracks_click_event_name' => $message->tracks->click->name,
324 'tracks_click_cta_name' => $message->tracks->click->props->cta_name,
325 'dismissible' => $message->is_dismissible,
326 'feature_class' => $message->feature_class,
327 'id' => $message->id,
328 );
329 }
330 }
331
332 /**
333 * Adds Jetpack menu.
334 */
335 public function add_jetpack_menu() {
336 // This is supposed to be the same as class-admin-menu but with a different position specified for the Jetpack menu.
337 if ( 'wp-admin' === get_option( 'wpcom_admin_interface' ) ) {
338 parent::create_jetpack_menu( 2, false );
339 } else {
340 parent::add_jetpack_menu();
341 }
342
343 /**
344 * Prevent duplicate menu items that link to Jetpack Backup.
345 * Hide the one that's shown when the standalone backup plugin is not installed, since Jetpack Backup is already included in Atomic sites.
346 *
347 * @see https://github.com/Automattic/jetpack/pull/33955
348 */
349 $this->hide_submenu_page( 'jetpack', esc_url( Redirect::get_url( 'calypso-backups' ) ) );
350 }
351
352 /**
353 * Adds Stats menu.
354 */
355 public function add_stats_menu() {
356 $menu_title = __( 'Stats', 'jetpack' );
357 if (
358 ! $this->is_api_request &&
359 \Jetpack::is_module_active( 'stats' ) &&
360 function_exists( 'stats_get_image_chart_src' )
361 ) {
362 $img_src = esc_attr(
363 stats_get_image_chart_src( 'admin-bar-hours-scale-2x', array( 'masterbar' => '' ) )
364 );
365 $alt = esc_attr__( 'Hourly views', 'jetpack' );
366
367 $menu_title .= "<img class='sidebar-unified__sparkline' src='$img_src' width='80' height='20' alt='$alt'>";
368 }
369
370 add_menu_page( __( 'Stats', 'jetpack' ), $menu_title, 'view_stats', 'https://wordpress.com/stats/day/' . $this->domain, null, 'dashicons-chart-bar', 3 );
371 }
372
373 /**
374 * Adds Upgrades menu.
375 *
376 * @param string $plan The current WPCOM plan of the blog.
377 */
378 public function add_upgrades_menu( $plan = null ) {
379
380 if ( get_option( 'wpcom_is_staging_site' ) ) {
381 return;
382 }
383 $products = Jetpack_Plan::get();
384 if ( array_key_exists( 'product_name_short', $products ) ) {
385 $plan = $products['product_name_short'];
386 }
387 parent::add_upgrades_menu( $plan );
388
389 $last_upgrade_submenu_position = $this->get_submenu_item_count( 'paid-upgrades.php' );
390
391 add_submenu_page( 'paid-upgrades.php', __( 'Domains', 'jetpack' ), __( 'Domains', 'jetpack' ), 'manage_options', 'https://wordpress.com/domains/manage/' . $this->domain, null, $last_upgrade_submenu_position - 1 );
392
393 /**
394 * Whether to show the WordPress.com Emails submenu under the main Upgrades menu.
395 *
396 * @use add_filter( 'jetpack_show_wpcom_upgrades_email_menu', '__return_true' );
397 * @module masterbar
398 *
399 * @since 9.7.0
400 *
401 * @param bool $show_wpcom_upgrades_email_menu Load the WordPress.com Emails submenu item. Default to false.
402 */
403 if ( apply_filters( 'jetpack_show_wpcom_upgrades_email_menu', false ) ) {
404 add_submenu_page( 'paid-upgrades.php', __( 'Emails', 'jetpack' ), __( 'Emails', 'jetpack' ), 'manage_options', 'https://wordpress.com/email/' . $this->domain, null, $last_upgrade_submenu_position );
405 }
406 }
407
408 /**
409 * Adds Settings menu.
410 */
411 public function add_options_menu() {
412 parent::add_options_menu();
413
414 if ( Jetpack_Plan::supports( 'security-settings' ) ) {
415 add_submenu_page(
416 'options-general.php',
417 esc_attr__( 'Security', 'jetpack' ),
418 __( 'Security', 'jetpack' ),
419 'manage_options',
420 'https://wordpress.com/settings/security/' . $this->domain,
421 null,
422 2
423 );
424 }
425
426 add_submenu_page( 'options-general.php', esc_attr__( 'Hosting Configuration', 'jetpack' ), __( 'Hosting Configuration', 'jetpack' ), 'manage_options', 'https://wordpress.com/hosting-config/' . $this->domain, null, 11 );
427
428 // Page Optimize is active by default on all Atomic sites and registers a Settings > Performance submenu which
429 // would conflict with our own Settings > Performance that links to Calypso, so we hide it it since the Calypso
430 // performance settings already have a link to Page Optimize settings page.
431 $this->hide_submenu_page( 'options-general.php', 'page-optimize' );
432 }
433
434 /**
435 * Adds Tools menu entries.
436 */
437 public function add_tools_menu() {
438 parent::add_tools_menu();
439
440 // Link the Tools menu to Available Tools when the interface is set to wp-admin.
441 if ( get_option( 'wpcom_admin_interface' ) === 'wp-admin' ) {
442 add_submenu_page( 'tools.php', esc_attr__( 'Available Tools', 'jetpack' ), __( 'Available Tools', 'jetpack' ), 'edit_posts', 'tools.php', null, 0 );
443 }
444
445 /**
446 * Adds the WordPress.com Site Monitoring submenu under the main Tools menu.
447 */
448 add_submenu_page( 'tools.php', esc_attr__( 'Site Monitoring', 'jetpack' ), __( 'Site Monitoring', 'jetpack' ), 'manage_options', 'https://wordpress.com/site-monitoring/' . $this->domain, null, 7 );
449
450 /**
451 * Adds the WordPress.com Github Deployments submenu under the main Tools menu.
452 */
453 if ( apply_filters( 'jetpack_show_wpcom_github_deployments_menu', false ) ) {
454 add_submenu_page( 'tools.php', esc_attr__( 'Github Deployments', 'jetpack' ), __( 'Github Deployments', 'jetpack' ), 'manage_options', 'https://wordpress.com/github-deployments/' . $this->domain, null, 7 );
455 }
456 }
457
458 /**
459 * Override the global submenu_file for theme-install.php page so the WP Admin menu item gets highlighted correctly.
460 *
461 * @param string $submenu_file The current pages $submenu_file global variable value.
462 * @return string | null
463 */
464 public function override_the_theme_installer( $submenu_file ) {
465 global $pagenow;
466
467 if ( 'themes.php' === $submenu_file && 'theme-install.php' === $pagenow ) {
468 return null;
469 }
470 return $submenu_file;
471 }
472
473 /**
474 * Also remove the Gutenberg plugin menu.
475 */
476 public function remove_gutenberg_menu() {
477 // Always remove the Gutenberg menu.
478 remove_menu_page( 'gutenberg' );
479 }
480
481 /**
482 * Saves the sidebar state ( expanded / collapsed ) via an ajax request.
483 */
484 public function ajax_sidebar_state() {
485 $expanded = isset( $_REQUEST['expanded'] ) ? filter_var( wp_unslash( $_REQUEST['expanded'] ), FILTER_VALIDATE_BOOLEAN ) : false; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
486 Client::wpcom_json_api_request_as_user(
487 '/me/preferences',
488 '2',
489 array(
490 'method' => 'POST',
491 ),
492 (object) array( 'calypso_preferences' => (object) array( 'sidebarCollapsed' => ! $expanded ) ),
493 'wpcom'
494 );
495
496 wp_die();
497 }
498
499 /**
500 * Handle ajax requests to dismiss a just-in-time-message
501 */
502 public function wp_ajax_jitm_dismiss() {
503 check_ajax_referer( 'jitm_dismiss' );
504 $jitm = \Automattic\Jetpack\JITMS\JITM::get_instance();
505 if ( isset( $_REQUEST['id'] ) && isset( $_REQUEST['feature_class'] ) ) {
506 $jitm->dismiss( sanitize_text_field( wp_unslash( $_REQUEST['id'] ) ), sanitize_text_field( wp_unslash( $_REQUEST['feature_class'] ) ) );
507 }
508 wp_die();
509 }
510
511 /**
512 * Adds a notice above each settings page while using the Classic view to indicate
513 * that the Default view offers more features. Links to the default view.
514 *
515 * @return void
516 */
517 public function add_settings_page_notice() {
518 if ( ! is_admin() ) {
519 return;
520 }
521
522 $current_screen = get_current_screen();
523
524 if ( ! $current_screen instanceof \WP_Screen ) {
525 return;
526 }
527
528 // Show the notice for the following screens and map them to the Calypso page.
529 $screen_map = array(
530 'options-general' => 'general',
531 'options-reading' => 'reading',
532 );
533
534 $mapped_screen = isset( $screen_map[ $current_screen->id ] )
535 ? $screen_map[ $current_screen->id ]
536 : false;
537
538 if ( ! $mapped_screen ) {
539 return;
540 }
541
542 $switch_url = sprintf( 'https://wordpress.com/settings/%s/%s', $mapped_screen, $this->domain );
543
544 // Close over the $switch_url variable.
545 $admin_notices = function () use ( $switch_url ) {
546 // translators: %s is a link to the Calypso settings page.
547 $notice = __( 'You are currently using the Classic view, which doesn\'t offer the same set of features as the Default view. To access additional settings and features, <a href="%s">switch to the Default view</a>. ', 'jetpack' );
548 ?>
549 <div class="notice notice-warning">
550 <p><?php echo wp_kses( sprintf( $notice, esc_url( $switch_url ) ), array( 'a' => array( 'href' => array() ) ) ); ?></p>
551 </div>
552 <?php
553 };
554
555 add_action( 'admin_notices', $admin_notices );
556 }
557
558 /**
559 * Adds Appearance menu.
560 */
561 public function add_appearance_menu() {
562 // When the interface is set to wp-admin, we need to add a link to the Marketplace and rest of the menu keeps like core.
563 if ( get_option( 'wpcom_admin_interface' ) === 'wp-admin' ) {
564 add_submenu_page( 'themes.php', esc_attr__( 'Theme Showcase', 'jetpack' ), __( 'Theme Showcase', 'jetpack' ), 'read', 'https://wordpress.com/themes/' . $this->domain );
565 } else {
566 parent::add_appearance_menu();
567 }
568 }
569
570 /**
571 * Adds a dashboard switcher to the list of screen meta links of the current page.
572 */
573 public function add_dashboard_switcher() {
574 // When the interface is set to wp-admin, do not show the dashboard switcher.
575 if ( get_option( 'wpcom_admin_interface' ) === 'wp-admin' ) {
576 return;
577 }
578
579 parent::add_dashboard_switcher();
580 }
581 }
582