PluginProbe ʕ •ᴥ•ʔ
Jetpack – WP Security, Backup, Speed, & Growth / 13.3.3
Jetpack – WP Security, Backup, Speed, & Growth v13.3.3
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
574 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 // We don't need the `My Mailboxes` when the interface is set to wp-admin or the site is a staging site,
79 if ( get_option( 'wpcom_admin_interface' ) !== 'wp-admin' && ! get_option( 'wpcom_is_staging_site' ) ) {
80 $this->add_my_mailboxes_menu();
81 }
82
83 // Not needed outside of wp-admin.
84 if ( ! $this->is_api_request ) {
85 $this->add_browse_sites_link();
86 $this->add_site_card_menu();
87 $this->add_new_site_link();
88 }
89
90 $this->add_woocommerce_installation_menu();
91 ksort( $GLOBALS['menu'] );
92 }
93
94 /**
95 * Get the preferred view for the given screen.
96 *
97 * @param string $screen Screen identifier.
98 * @param bool $fallback_global_preference (Optional) Whether the global preference for all screens should be used
99 * as fallback if there is no specific preference for the given screen.
100 * Default: true.
101 * @return string
102 */
103 public function get_preferred_view( $screen, $fallback_global_preference = true ) {
104
105 // Export on Atomic sites are always managed on WP Admin.
106 if ( in_array( $screen, array( 'export.php' ), true ) ) {
107 return self::CLASSIC_VIEW;
108 }
109
110 /**
111 * When Jetpack SSO is disabled, we need to force Calypso because it might create confusion to be redirected to WP-Admin.
112 * 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.
113 */
114 if ( ! \Jetpack::is_module_active( 'sso' ) ) {
115 return self::DEFAULT_VIEW;
116 }
117
118 return parent::get_preferred_view( $screen, $fallback_global_preference );
119 }
120
121 /**
122 * Adds Users menu.
123 */
124 public function add_users_menu() {
125 $slug = current_user_can( 'list_users' ) ? 'users.php' : 'profile.php';
126 if ( self::DEFAULT_VIEW === $this->get_preferred_view( 'users.php' ) ) {
127 $submenus_to_update = array(
128 'users.php' => 'https://wordpress.com/people/team/' . $this->domain,
129 );
130 $this->update_submenus( $slug, $submenus_to_update );
131 }
132
133 if ( ! $this->use_wp_admin_interface() ) {
134 // The 'Subscribers' menu exists in the Jetpack menu for Classic wp-admin interface, so only add it for non-wp-admin interfaces.
135 add_submenu_page( 'users.php', esc_attr__( 'Subscribers', 'jetpack' ), __( 'Subscribers', 'jetpack' ), 'list_users', 'https://wordpress.com/subscribers/' . $this->domain, null );
136
137 // When the interface is not set to wp-admin, we replace the Profile submenu.
138 remove_submenu_page( 'users.php', 'profile.php' );
139 add_submenu_page( 'users.php', esc_attr__( 'My Profile', 'jetpack' ), __( 'My Profile', 'jetpack' ), 'read', 'https://wordpress.com/me/', null );
140 }
141
142 // Users who can't 'list_users' will see "Profile" menu & "Profile > Account Settings" as submenu.
143 add_submenu_page( $slug, esc_attr__( 'Account Settings', 'jetpack' ), __( 'Account Settings', 'jetpack' ), 'read', 'https://wordpress.com/me/account' );
144 }
145
146 /**
147 * Adds Plugins menu.
148 */
149 public function add_plugins_menu() {
150
151 global $submenu;
152
153 // Calypso plugins screens link.
154 $plugins_slug = 'https://wordpress.com/plugins/' . $this->domain;
155
156 // Link to the Marketplace from Plugins > Add New on Atomic sites where the wpcom_admin_interface option is set to wp-admin.
157 if ( self::CLASSIC_VIEW === $this->get_preferred_view( 'plugins.php' ) ) {
158 $submenus_to_update = array( 'plugin-install.php' => $plugins_slug );
159 $this->update_submenus( 'plugins.php', $submenus_to_update );
160 return;
161 }
162
163 // Link to the Marketplace on sites that can't manage plugins.
164 if (
165 function_exists( 'wpcom_site_has_feature' ) &&
166 ! wpcom_site_has_feature( \WPCOM_Features::MANAGE_PLUGINS )
167 ) {
168 add_menu_page( __( 'Plugins', 'jetpack' ), __( 'Plugins', 'jetpack' ), 'manage_options', $plugins_slug, null, 'dashicons-admin-plugins', '65' );
169 return;
170 }
171
172 if ( ! isset( $submenu['plugins.php'] ) ) {
173 return;
174 }
175
176 $plugins_submenu = $submenu['plugins.php'];
177
178 // Move "Add New" plugin submenu to the top position.
179 foreach ( $plugins_submenu as $submenu_key => $submenu_keys ) {
180 if ( 'plugin-install.php' === $submenu_keys[2] ) {
181 // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
182 $submenu['plugins.php'] = array( $submenu_key => $plugins_submenu[ $submenu_key ] ) + $plugins_submenu;
183 }
184 }
185
186 $submenus_to_update = array( 'plugin-install.php' => $plugins_slug );
187
188 $this->update_submenus( 'plugins.php', $submenus_to_update );
189 }
190
191 /**
192 * Adds the site switcher link if user has more than one site.
193 */
194 public function add_browse_sites_link() {
195 $site_count = get_user_option( 'wpcom_site_count' );
196 if ( ! $site_count || $site_count < 2 ) {
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 // Hide Settings > Performance when the interface is set to wp-admin.
434 // This is due to these settings are mostly also available in Jetpack > Settings, in the Performance tab.
435 if ( get_option( 'wpcom_admin_interface' ) === 'wp-admin' ) {
436 $this->hide_submenu_page( 'options-general.php', 'https://wordpress.com/settings/performance/' . $this->domain );
437 }
438 }
439
440 /**
441 * Adds Tools menu entries.
442 */
443 public function add_tools_menu() {
444 parent::add_tools_menu();
445
446 // Link the Tools menu to Available Tools when the interface is set to wp-admin.
447 if ( get_option( 'wpcom_admin_interface' ) === 'wp-admin' ) {
448 add_submenu_page( 'tools.php', esc_attr__( 'Available Tools', 'jetpack' ), __( 'Available Tools', 'jetpack' ), 'edit_posts', 'tools.php', null, 0 );
449 }
450
451 /**
452 * Adds the WordPress.com Site Monitoring submenu under the main Tools menu.
453 */
454 add_submenu_page( 'tools.php', esc_attr__( 'Site Monitoring', 'jetpack' ), __( 'Site Monitoring', 'jetpack' ), 'manage_options', 'https://wordpress.com/site-monitoring/' . $this->domain, null, 7 );
455
456 /**
457 * Adds the WordPress.com GitHub Deployments submenu under the main Tools menu.
458 */
459 add_submenu_page( 'tools.php', esc_attr__( 'GitHub Deployments', 'jetpack' ), __( 'GitHub Deployments', 'jetpack' ), 'manage_options', 'https://wordpress.com/github-deployments/' . $this->domain, null, 8 );
460 }
461
462 /**
463 * Override the global submenu_file for theme-install.php page so the WP Admin menu item gets highlighted correctly.
464 *
465 * @param string $submenu_file The current pages $submenu_file global variable value.
466 * @return string | null
467 */
468 public function override_the_theme_installer( $submenu_file ) {
469 global $pagenow;
470
471 if ( 'themes.php' === $submenu_file && 'theme-install.php' === $pagenow ) {
472 return null;
473 }
474 return $submenu_file;
475 }
476
477 /**
478 * Also remove the Gutenberg plugin menu.
479 */
480 public function remove_gutenberg_menu() {
481 // Always remove the Gutenberg menu.
482 remove_menu_page( 'gutenberg' );
483 }
484
485 /**
486 * Saves the sidebar state ( expanded / collapsed ) via an ajax request.
487 */
488 public function ajax_sidebar_state() {
489 $expanded = isset( $_REQUEST['expanded'] ) ? filter_var( wp_unslash( $_REQUEST['expanded'] ), FILTER_VALIDATE_BOOLEAN ) : false; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
490 Client::wpcom_json_api_request_as_user(
491 '/me/preferences',
492 '2',
493 array(
494 'method' => 'POST',
495 ),
496 (object) array( 'calypso_preferences' => (object) array( 'sidebarCollapsed' => ! $expanded ) ),
497 'wpcom'
498 );
499
500 wp_die();
501 }
502
503 /**
504 * Handle ajax requests to dismiss a just-in-time-message
505 */
506 public function wp_ajax_jitm_dismiss() {
507 check_ajax_referer( 'jitm_dismiss' );
508 $jitm = \Automattic\Jetpack\JITMS\JITM::get_instance();
509 if ( isset( $_REQUEST['id'] ) && isset( $_REQUEST['feature_class'] ) ) {
510 $jitm->dismiss( sanitize_text_field( wp_unslash( $_REQUEST['id'] ) ), sanitize_text_field( wp_unslash( $_REQUEST['feature_class'] ) ) );
511 }
512 wp_die();
513 }
514
515 /**
516 * Adds a notice above each settings page while using the Classic view to indicate
517 * that the Default view offers more features. Links to the default view.
518 *
519 * @return void
520 */
521 public function add_settings_page_notice() {
522 if ( ! is_admin() ) {
523 return;
524 }
525
526 $current_screen = get_current_screen();
527
528 if ( ! $current_screen instanceof \WP_Screen ) {
529 return;
530 }
531
532 // Show the notice for the following screens and map them to the Calypso page.
533 $screen_map = array(
534 'options-general' => 'general',
535 'options-reading' => 'reading',
536 );
537
538 $mapped_screen = isset( $screen_map[ $current_screen->id ] )
539 ? $screen_map[ $current_screen->id ]
540 : false;
541
542 if ( ! $mapped_screen ) {
543 return;
544 }
545
546 $switch_url = sprintf( 'https://wordpress.com/settings/%s/%s', $mapped_screen, $this->domain );
547
548 // Close over the $switch_url variable.
549 $admin_notices = function () use ( $switch_url ) {
550 // translators: %s is a link to the Calypso settings page.
551 $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' );
552 ?>
553 <div class="notice notice-warning">
554 <p><?php echo wp_kses( sprintf( $notice, esc_url( $switch_url ) ), array( 'a' => array( 'href' => array() ) ) ); ?></p>
555 </div>
556 <?php
557 };
558
559 add_action( 'admin_notices', $admin_notices );
560 }
561
562 /**
563 * Adds Appearance menu.
564 */
565 public function add_appearance_menu() {
566 // 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.
567 if ( get_option( 'wpcom_admin_interface' ) === 'wp-admin' ) {
568 add_submenu_page( 'themes.php', esc_attr__( 'Theme Showcase', 'jetpack' ), __( 'Theme Showcase', 'jetpack' ), 'read', 'https://wordpress.com/themes/' . $this->domain );
569 } else {
570 parent::add_appearance_menu();
571 }
572 }
573 }
574