PluginProbe ʕ •ᴥ•ʔ
Jetpack – WP Security, Backup, Speed, & Growth / 13.2.4
Jetpack – WP Security, Backup, Speed, & Growth v13.2.4
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
580 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 add_submenu_page( 'users.php', esc_attr__( 'Subscribers', 'jetpack' ), __( 'Subscribers', 'jetpack' ), 'list_users', 'https://wordpress.com/subscribers/' . $this->domain, null );
134
135 // When the interface is not set to wp-admin, we replace the Profile submenu.
136 if ( ! $this->use_wp_admin_interface() ) {
137 remove_submenu_page( 'users.php', 'profile.php' );
138 add_submenu_page( 'users.php', esc_attr__( 'My Profile', 'jetpack' ), __( 'My Profile', 'jetpack' ), 'read', 'https://wordpress.com/me/', null );
139 }
140
141 // Users who can't 'list_users' will see "Profile" menu & "Profile > Account Settings" as submenu.
142 add_submenu_page( $slug, esc_attr__( 'Account Settings', 'jetpack' ), __( 'Account Settings', 'jetpack' ), 'read', 'https://wordpress.com/me/account' );
143 }
144
145 /**
146 * Adds Plugins menu.
147 */
148 public function add_plugins_menu() {
149
150 global $submenu;
151
152 // Calypso plugins screens link.
153 $plugins_slug = 'https://wordpress.com/plugins/' . $this->domain;
154
155 // Link to the Marketplace from Plugins > Add New on Atomic sites where the wpcom_admin_interface option is set to wp-admin.
156 if ( self::CLASSIC_VIEW === $this->get_preferred_view( 'plugins.php' ) ) {
157 $submenus_to_update = array( 'plugin-install.php' => $plugins_slug );
158 $this->update_submenus( 'plugins.php', $submenus_to_update );
159 return;
160 }
161
162 // Link to the Marketplace on sites that can't manage plugins.
163 if (
164 function_exists( 'wpcom_site_has_feature' ) &&
165 ! wpcom_site_has_feature( \WPCOM_Features::MANAGE_PLUGINS )
166 ) {
167 add_menu_page( __( 'Plugins', 'jetpack' ), __( 'Plugins', 'jetpack' ), 'manage_options', $plugins_slug, null, 'dashicons-admin-plugins', '65' );
168 return;
169 }
170
171 if ( ! isset( $submenu['plugins.php'] ) ) {
172 return;
173 }
174
175 $plugins_submenu = $submenu['plugins.php'];
176
177 // Move "Add New" plugin submenu to the top position.
178 foreach ( $plugins_submenu as $submenu_key => $submenu_keys ) {
179 if ( 'plugin-install.php' === $submenu_keys[2] ) {
180 // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
181 $submenu['plugins.php'] = array( $submenu_key => $plugins_submenu[ $submenu_key ] ) + $plugins_submenu;
182 }
183 }
184
185 $submenus_to_update = array( 'plugin-install.php' => $plugins_slug );
186
187 $this->update_submenus( 'plugins.php', $submenus_to_update );
188 }
189
190 /**
191 * Adds the site switcher link if user has more than one site.
192 */
193 public function add_browse_sites_link() {
194 $site_count = get_user_option( 'wpcom_site_count' );
195 if ( ! $site_count || $site_count < 2 ) {
196 return;
197 }
198
199 // Unnecessary because "My Sites" always links to the Sites page.
200 if ( 'wp-admin' === get_option( 'wpcom_admin_interface' ) ) {
201 return;
202 }
203
204 // Add the menu item.
205 add_menu_page( __( 'site-switcher', 'jetpack' ), __( 'Browse sites', 'jetpack' ), 'read', 'https://wordpress.com/sites', null, 'dashicons-arrow-left-alt2', 0 );
206 add_filter( 'add_menu_classes', array( $this, 'set_browse_sites_link_class' ) );
207 }
208
209 /**
210 * Adds a custom element class for Site Switcher menu item.
211 *
212 * @param array $menu Associative array of administration menu items.
213 *
214 * @return array
215 */
216 public function set_browse_sites_link_class( array $menu ) {
217 foreach ( $menu as $key => $menu_item ) {
218 if ( 'site-switcher' !== $menu_item[3] ) {
219 continue;
220 }
221
222 $menu[ $key ][4] = add_cssclass( 'site-switcher', $menu_item[4] );
223 break;
224 }
225
226 return $menu;
227 }
228
229 /**
230 * Adds a link to the menu to create a new site.
231 */
232 public function add_new_site_link() {
233 $site_count = get_user_option( 'wpcom_site_count' );
234 if ( $site_count && $site_count > 1 ) {
235 return;
236 }
237
238 add_menu_page( __( 'Add New Site', 'jetpack' ), __( 'Add New Site', 'jetpack' ), 'read', 'https://wordpress.com/start?ref=calypso-sidebar', null, 'dashicons-plus-alt' );
239 }
240
241 /**
242 * Adds site card component.
243 */
244 public function add_site_card_menu() {
245 $default = plugins_url( 'globe-icon.svg', __FILE__ );
246 $icon = get_site_icon_url( 32, $default );
247 $blog_name = get_option( 'blogname' ) !== '' ? get_option( 'blogname' ) : $this->domain;
248 $is_coming_soon = ( new Status() )->is_coming_soon();
249
250 $badge = '';
251
252 if ( get_option( 'wpcom_is_staging_site' ) ) {
253 $badge .= '<span class="site__badge site__badge-staging">' . esc_html__( 'Staging', 'jetpack' ) . '</span>';
254 }
255
256 if ( ( function_exists( 'site_is_private' ) && site_is_private() ) || $is_coming_soon ) {
257 $badge .= sprintf(
258 '<span class="site__badge site__badge-private">%s</span>',
259 $is_coming_soon ? esc_html__( 'Coming Soon', 'jetpack' ) : esc_html__( 'Private', 'jetpack' )
260 );
261 }
262
263 $site_card = '
264 <div class="site__info">
265 <div class="site__title">%1$s</div>
266 <div class="site__domain">%2$s</div>
267 %3$s
268 </div>';
269
270 $site_card = sprintf(
271 $site_card,
272 $blog_name,
273 $this->domain,
274 $badge
275 );
276
277 add_menu_page( 'site-card', $site_card, 'read', get_home_url(), null, $icon, 1 );
278 add_filter( 'add_menu_classes', array( $this, 'set_site_card_menu_class' ) );
279 }
280
281 /**
282 * Adds a custom element class and id for Site Card's menu item.
283 *
284 * @param array $menu Associative array of administration menu items.
285 *
286 * @return array
287 */
288 public function set_site_card_menu_class( array $menu ) {
289 foreach ( $menu as $key => $menu_item ) {
290 if ( 'site-card' !== $menu_item[3] ) {
291 continue;
292 }
293
294 $classes = ' toplevel_page_site-card';
295
296 // webclip.png is the default on WoA sites. Anything other than that means we have a custom site icon.
297 if ( has_site_icon() && 'https://s0.wp.com/i/webclip.png' !== get_site_icon_url( 512 ) ) {
298 $classes .= ' has-site-icon';
299 }
300
301 $menu[ $key ][4] = $menu_item[4] . $classes;
302 $menu[ $key ][5] = 'toplevel_page_site_card';
303 break;
304 }
305
306 return $menu;
307 }
308
309 /**
310 * Returns the first available upsell nudge.
311 *
312 * @return array
313 */
314 public function get_upsell_nudge() {
315 $jitm = \Automattic\Jetpack\JITMS\JITM::get_instance();
316 $message_path = 'calypso:sites:sidebar_notice';
317 $message = $jitm->get_messages( $message_path, wp_json_encode( array( 'message_path' => $message_path ) ), false );
318
319 if ( isset( $message[0] ) ) {
320 $message = $message[0];
321 return array(
322 'content' => $message->content->message,
323 'cta' => $message->CTA->message, // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
324 'link' => $message->CTA->link, // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
325 'tracks_impression_event_name' => $message->tracks->display->name,
326 'tracks_impression_cta_name' => $message->tracks->display->props->cta_name,
327 'tracks_click_event_name' => $message->tracks->click->name,
328 'tracks_click_cta_name' => $message->tracks->click->props->cta_name,
329 'dismissible' => $message->is_dismissible,
330 'feature_class' => $message->feature_class,
331 'id' => $message->id,
332 );
333 }
334 }
335
336 /**
337 * Adds Jetpack menu.
338 */
339 public function add_jetpack_menu() {
340 // This is supposed to be the same as class-admin-menu but with a different position specified for the Jetpack menu.
341 if ( 'wp-admin' === get_option( 'wpcom_admin_interface' ) ) {
342 parent::create_jetpack_menu( 2, false );
343 } else {
344 parent::add_jetpack_menu();
345 }
346
347 /**
348 * Prevent duplicate menu items that link to Jetpack Backup.
349 * Hide the one that's shown when the standalone backup plugin is not installed, since Jetpack Backup is already included in Atomic sites.
350 *
351 * @see https://github.com/Automattic/jetpack/pull/33955
352 */
353 $this->hide_submenu_page( 'jetpack', esc_url( Redirect::get_url( 'calypso-backups' ) ) );
354 }
355
356 /**
357 * Adds Stats menu.
358 */
359 public function add_stats_menu() {
360 $menu_title = __( 'Stats', 'jetpack' );
361 if (
362 ! $this->is_api_request &&
363 \Jetpack::is_module_active( 'stats' ) &&
364 function_exists( 'stats_get_image_chart_src' )
365 ) {
366 $img_src = esc_attr(
367 stats_get_image_chart_src( 'admin-bar-hours-scale-2x', array( 'masterbar' => '' ) )
368 );
369 $alt = esc_attr__( 'Hourly views', 'jetpack' );
370
371 $menu_title .= "<img class='sidebar-unified__sparkline' src='$img_src' width='80' height='20' alt='$alt'>";
372 }
373
374 add_menu_page( __( 'Stats', 'jetpack' ), $menu_title, 'view_stats', 'https://wordpress.com/stats/day/' . $this->domain, null, 'dashicons-chart-bar', 3 );
375 }
376
377 /**
378 * Adds Upgrades menu.
379 *
380 * @param string $plan The current WPCOM plan of the blog.
381 */
382 public function add_upgrades_menu( $plan = null ) {
383
384 if ( get_option( 'wpcom_is_staging_site' ) ) {
385 return;
386 }
387 $products = Jetpack_Plan::get();
388 if ( array_key_exists( 'product_name_short', $products ) ) {
389 $plan = $products['product_name_short'];
390 }
391 parent::add_upgrades_menu( $plan );
392
393 $last_upgrade_submenu_position = $this->get_submenu_item_count( 'paid-upgrades.php' );
394
395 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 );
396
397 /**
398 * Whether to show the WordPress.com Emails submenu under the main Upgrades menu.
399 *
400 * @use add_filter( 'jetpack_show_wpcom_upgrades_email_menu', '__return_true' );
401 * @module masterbar
402 *
403 * @since 9.7.0
404 *
405 * @param bool $show_wpcom_upgrades_email_menu Load the WordPress.com Emails submenu item. Default to false.
406 */
407 if ( apply_filters( 'jetpack_show_wpcom_upgrades_email_menu', false ) ) {
408 add_submenu_page( 'paid-upgrades.php', __( 'Emails', 'jetpack' ), __( 'Emails', 'jetpack' ), 'manage_options', 'https://wordpress.com/email/' . $this->domain, null, $last_upgrade_submenu_position );
409 }
410 }
411
412 /**
413 * Adds Settings menu.
414 */
415 public function add_options_menu() {
416 parent::add_options_menu();
417
418 if ( Jetpack_Plan::supports( 'security-settings' ) ) {
419 add_submenu_page(
420 'options-general.php',
421 esc_attr__( 'Security', 'jetpack' ),
422 __( 'Security', 'jetpack' ),
423 'manage_options',
424 'https://wordpress.com/settings/security/' . $this->domain,
425 null,
426 2
427 );
428 }
429
430 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 );
431
432 // Page Optimize is active by default on all Atomic sites and registers a Settings > Performance submenu which
433 // would conflict with our own Settings > Performance that links to Calypso, so we hide it it since the Calypso
434 // performance settings already have a link to Page Optimize settings page.
435 $this->hide_submenu_page( 'options-general.php', 'page-optimize' );
436
437 // Hide Settings > Performance when the interface is set to wp-admin.
438 // This is due to these settings are mostly also available in Jetpack > Settings, in the Performance tab.
439 if ( get_option( 'wpcom_admin_interface' ) === 'wp-admin' ) {
440 $this->hide_submenu_page( 'options-general.php', 'https://wordpress.com/settings/performance/' . $this->domain );
441 }
442 }
443
444 /**
445 * Adds Tools menu entries.
446 */
447 public function add_tools_menu() {
448 parent::add_tools_menu();
449
450 // Link the Tools menu to Available Tools when the interface is set to wp-admin.
451 if ( get_option( 'wpcom_admin_interface' ) === 'wp-admin' ) {
452 add_submenu_page( 'tools.php', esc_attr__( 'Available Tools', 'jetpack' ), __( 'Available Tools', 'jetpack' ), 'edit_posts', 'tools.php', null, 0 );
453 }
454
455 /**
456 * Adds the WordPress.com Site Monitoring submenu under the main Tools menu.
457 */
458 add_submenu_page( 'tools.php', esc_attr__( 'Site Monitoring', 'jetpack' ), __( 'Site Monitoring', 'jetpack' ), 'manage_options', 'https://wordpress.com/site-monitoring/' . $this->domain, null, 7 );
459
460 /**
461 * Adds the WordPress.com GitHub Deployments submenu under the main Tools menu.
462 */
463 if ( apply_filters( 'jetpack_show_wpcom_github_deployments_menu', false ) ) {
464 add_submenu_page( 'tools.php', esc_attr__( 'GitHub Deployments', 'jetpack' ), __( 'GitHub Deployments', 'jetpack' ), 'manage_options', 'https://wordpress.com/github-deployments/' . $this->domain, null, 7 );
465 }
466 }
467
468 /**
469 * Override the global submenu_file for theme-install.php page so the WP Admin menu item gets highlighted correctly.
470 *
471 * @param string $submenu_file The current pages $submenu_file global variable value.
472 * @return string | null
473 */
474 public function override_the_theme_installer( $submenu_file ) {
475 global $pagenow;
476
477 if ( 'themes.php' === $submenu_file && 'theme-install.php' === $pagenow ) {
478 return null;
479 }
480 return $submenu_file;
481 }
482
483 /**
484 * Also remove the Gutenberg plugin menu.
485 */
486 public function remove_gutenberg_menu() {
487 // Always remove the Gutenberg menu.
488 remove_menu_page( 'gutenberg' );
489 }
490
491 /**
492 * Saves the sidebar state ( expanded / collapsed ) via an ajax request.
493 */
494 public function ajax_sidebar_state() {
495 $expanded = isset( $_REQUEST['expanded'] ) ? filter_var( wp_unslash( $_REQUEST['expanded'] ), FILTER_VALIDATE_BOOLEAN ) : false; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
496 Client::wpcom_json_api_request_as_user(
497 '/me/preferences',
498 '2',
499 array(
500 'method' => 'POST',
501 ),
502 (object) array( 'calypso_preferences' => (object) array( 'sidebarCollapsed' => ! $expanded ) ),
503 'wpcom'
504 );
505
506 wp_die();
507 }
508
509 /**
510 * Handle ajax requests to dismiss a just-in-time-message
511 */
512 public function wp_ajax_jitm_dismiss() {
513 check_ajax_referer( 'jitm_dismiss' );
514 $jitm = \Automattic\Jetpack\JITMS\JITM::get_instance();
515 if ( isset( $_REQUEST['id'] ) && isset( $_REQUEST['feature_class'] ) ) {
516 $jitm->dismiss( sanitize_text_field( wp_unslash( $_REQUEST['id'] ) ), sanitize_text_field( wp_unslash( $_REQUEST['feature_class'] ) ) );
517 }
518 wp_die();
519 }
520
521 /**
522 * Adds a notice above each settings page while using the Classic view to indicate
523 * that the Default view offers more features. Links to the default view.
524 *
525 * @return void
526 */
527 public function add_settings_page_notice() {
528 if ( ! is_admin() ) {
529 return;
530 }
531
532 $current_screen = get_current_screen();
533
534 if ( ! $current_screen instanceof \WP_Screen ) {
535 return;
536 }
537
538 // Show the notice for the following screens and map them to the Calypso page.
539 $screen_map = array(
540 'options-general' => 'general',
541 'options-reading' => 'reading',
542 );
543
544 $mapped_screen = isset( $screen_map[ $current_screen->id ] )
545 ? $screen_map[ $current_screen->id ]
546 : false;
547
548 if ( ! $mapped_screen ) {
549 return;
550 }
551
552 $switch_url = sprintf( 'https://wordpress.com/settings/%s/%s', $mapped_screen, $this->domain );
553
554 // Close over the $switch_url variable.
555 $admin_notices = function () use ( $switch_url ) {
556 // translators: %s is a link to the Calypso settings page.
557 $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' );
558 ?>
559 <div class="notice notice-warning">
560 <p><?php echo wp_kses( sprintf( $notice, esc_url( $switch_url ) ), array( 'a' => array( 'href' => array() ) ) ); ?></p>
561 </div>
562 <?php
563 };
564
565 add_action( 'admin_notices', $admin_notices );
566 }
567
568 /**
569 * Adds Appearance menu.
570 */
571 public function add_appearance_menu() {
572 // 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.
573 if ( get_option( 'wpcom_admin_interface' ) === 'wp-admin' ) {
574 add_submenu_page( 'themes.php', esc_attr__( 'Theme Showcase', 'jetpack' ), __( 'Theme Showcase', 'jetpack' ), 'read', 'https://wordpress.com/themes/' . $this->domain );
575 } else {
576 parent::add_appearance_menu();
577 }
578 }
579 }
580