PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 10.2.3
Jetpack – WP Security, Backup, Speed, & Growth v10.2.3
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 14.1.1 14.2.2 14.3.1 All 501 releases
jetpack / modules / masterbar / admin-menu / load.php
load.php
117 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Admin Menu loader.
4 *
5 * @package Jetpack
6 */
7
8 namespace Automattic\Jetpack\Dashboard_Customizations;
9
10 use Automattic\Jetpack\Tracking;
11
12 /**
13 * Checks whether the navigation customizations should be performed for the given class.
14 *
15 * @param string $admin_menu_class Class name.
16 *
17 * @return bool
18 */
19 function should_customize_nav( $admin_menu_class ) {
20 // Make sure the class extends the base admin menu class.
21 if ( ! is_subclass_of( $admin_menu_class, Base_Admin_Menu::class ) ) {
22 return false;
23 }
24
25 $is_api_request = defined( 'REST_REQUEST' ) && REST_REQUEST || 0 === strpos( $_SERVER['REQUEST_URI'], '/?rest_route=%2Fwpcom%2Fv2%2Fadmin-menu' );
26
27 // No nav customizations on WP Admin of Atomic sites when SSO is disabled.
28 if ( is_a( $admin_menu_class, Atomic_Admin_Menu::class, true ) && ! $is_api_request && ! \Jetpack::is_module_active( 'sso' ) ) {
29 return false;
30 }
31
32 // No nav customizations on WP Admin of Jetpack sites.
33 if ( is_a( $admin_menu_class, Jetpack_Admin_Menu::class, true ) && ! $is_api_request ) {
34 return false;
35 }
36
37 return true;
38 }
39
40 /**
41 * Gets the name of the class that customizes the admin menu.
42 *
43 * @return string Class name.
44 */
45 function get_admin_menu_class() {
46 // WordPress.com Atomic sites.
47 if ( jetpack_is_atomic_site() ) {
48 require_once __DIR__ . '/class-atomic-admin-menu.php';
49 return Atomic_Admin_Menu::class;
50 }
51
52 // WordPress.com Simple sites.
53 if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
54 $blog_id = get_current_blog_id();
55
56 // Domain-only sites.
57 $blog_options = get_blog_option( $blog_id, 'options' );
58 $is_domain_only = ! empty( $blog_options['is_domain_only'] );
59 if ( $is_domain_only ) {
60 require_once __DIR__ . '/class-domain-only-admin-menu.php';
61 return Domain_Only_Admin_Menu::class;
62 }
63
64 // P2 sites.
65 require_once WP_CONTENT_DIR . '/lib/wpforteams/functions.php';
66 if ( \WPForTeams\is_wpforteams_site( $blog_id ) ) {
67 require_once __DIR__ . '/class-p2-admin-menu.php';
68 return P2_Admin_Menu::class;
69 }
70
71 // Rest of simple sites.
72 require_once __DIR__ . '/class-wpcom-admin-menu.php';
73 return WPcom_Admin_Menu::class;
74 }
75
76 // Jetpack sites.
77 require_once __DIR__ . '/class-jetpack-admin-menu.php';
78 return Jetpack_Admin_Menu::class;
79 }
80
81 /**
82 * Filters the name of the class that customizes the admin menu. It should extends the `Base_Admin_Menu` class.
83 *
84 * @module masterbar
85 *
86 * @since 9.6.0
87 *
88 * @param string $admin_menu_class Class name.
89 */
90 $admin_menu_class = apply_filters( 'jetpack_admin_menu_class', get_admin_menu_class() );
91 if ( should_customize_nav( $admin_menu_class ) ) {
92 /** The admin menu singleton instance. @var Base_Admin_Menu $instance */
93 $admin_menu_class::get_instance();
94
95 /**
96 * Trigger an event when the user uses the dashboard quick switcher.
97 *
98 * @param string $screen The current screen.
99 * @param string $view The view the user choosed to go to.
100 */
101 function dashboard_quick_switcher_record_usage( $screen, $view ) {
102 require_once __DIR__ . '/class-dashboard-switcher-tracking.php';
103
104 $tracking = new Dashboard_Switcher_Tracking(
105 new Tracking( Dashboard_Switcher_Tracking::get_jetpack_tracking_product() ),
106 array( Dashboard_Switcher_Tracking::class, 'wpcom_tracks_record_event' ),
107 Dashboard_Switcher_Tracking::get_plan()
108 );
109
110 $tracking->record_switch_event( $screen, $view );
111 }
112
113 \add_action( 'jetpack_dashboard_switcher_changed_view', __NAMESPACE__ . '\dashboard_quick_switcher_record_usage', 10, 2 );
114 } else {
115 \add_filter( 'jetpack_load_admin_menu_class', '__return_false' );
116 }
117