PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-a.7
Jetpack – WP Security, Backup, Speed, & Growth v16.3-a.7
16.3-a.5 16.3-a.7 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 All 506 releases
← All changes | class.jetpack-admin.php +154 -44 13.4.5 → 16.3-a.7 View file →
@@ -10,8 +10,12 @@
10 10 use Automattic\Jetpack\Partner_Coupon as Jetpack_Partner_Coupon;
11 11 use Automattic\Jetpack\Status;
12 12 use Automattic\Jetpack\Status\Host;
13 13
14 +if ( ! defined( 'ABSPATH' ) ) {
15 + exit( 0 );
16 +}
17 +
14 18 /**
15 19 * Build the Jetpack admin menu as a whole.
16 20 */
17 21 class Jetpack_Admin {
@@ -28,13 +32,8 @@
28 32 *
29 33 * @return self
30 34 */
31 35 public static function init() {
32 - // phpcs:ignore WordPress.Security.NonceVerification.Recommended
33 - if ( isset( $_GET['page'] ) && 'jetpack' === $_GET['page'] ) {
34 - add_filter( 'nocache_headers', array( 'Jetpack_Admin', 'add_no_store_header' ), 100 );
35 - }
36 -
37 36 if ( self::$instance === null ) {
38 37 self::$instance = new Jetpack_Admin();
39 38 }
40 39 return self::$instance;
@@ -42,12 +41,14 @@
42 41
43 42 /**
44 43 * Filter callback to add `no-store` to the `Cache-Control` header.
45 44 *
45 + * @deprecated 14.9
46 46 * @param array $headers Headers array.
47 47 * @return array Modified headers array.
48 48 */
49 49 public static function add_no_store_header( $headers ) {
50 + _deprecated_function( __METHOD__, '14.9' );
50 51 $headers['Cache-Control'] .= ', no-store';
51 52 return $headers;
52 53 }
53 54
@@ -55,8 +56,11 @@
55 56 private function __construct() {
56 57 require_once JETPACK__PLUGIN_DIR . '_inc/lib/admin-pages/class.jetpack-react-page.php';
57 58 $jetpack_react = new Jetpack_React_Page();
58 59
60 + require_once JETPACK__PLUGIN_DIR . '_inc/lib/admin-pages/class-jetpack-settings-react-page.php';
61 + $jetpack_settings = new Jetpack_Settings_React_Page();
62 +
59 63 require_once JETPACK__PLUGIN_DIR . '_inc/lib/admin-pages/class.jetpack-settings-page.php';
60 64 $fallback_page = new Jetpack_Settings_Page();
61 65
62 66 require_once JETPACK__PLUGIN_DIR . '_inc/lib/admin-pages/class-jetpack-about-page.php';
@@ -61,15 +65,20 @@
61 65
62 66 require_once JETPACK__PLUGIN_DIR . '_inc/lib/admin-pages/class-jetpack-about-page.php';
63 67 $jetpack_about = new Jetpack_About_Page();
64 68
69 + require_once JETPACK__PLUGIN_DIR . '_inc/lib/admin-pages/class-jetpack-ai-page.php';
70 + $jetpack_ai = new Jetpack_AI_Page();
71 +
65 72 add_action( 'admin_init', array( $jetpack_react, 'react_redirects' ), 0 );
66 73 add_action( 'admin_menu', array( $jetpack_react, 'add_actions' ), 998 );
67 - add_action( 'jetpack_admin_menu', array( $jetpack_react, 'jetpack_add_dashboard_sub_nav_item' ) );
68 - add_action( 'jetpack_admin_menu', array( $jetpack_react, 'jetpack_add_settings_sub_nav_item' ) );
74 + add_action( 'admin_menu', array( $jetpack_react, 'remove_jetpack_menu' ), 2000 );
75 + add_action( 'admin_menu', array( $jetpack_settings, 'maybe_load_wp_build' ), 1 );
76 + add_action( 'jetpack_admin_menu', array( $jetpack_settings, 'add_actions' ) );
69 77 add_action( 'jetpack_admin_menu', array( $this, 'admin_menu_debugger' ) );
70 78 add_action( 'jetpack_admin_menu', array( $fallback_page, 'add_actions' ) );
71 79 add_action( 'jetpack_admin_menu', array( $jetpack_about, 'add_actions' ) );
80 + add_action( 'jetpack_admin_menu', array( $jetpack_ai, 'add_actions' ) );
72 81
73 82 // Add redirect to current page for activation/deactivation of modules.
74 83 add_action( 'jetpack_pre_activate_module', array( $this, 'fix_redirect' ), 10, 2 );
75 84 add_action( 'jetpack_pre_deactivate_module', array( $this, 'fix_redirect' ), 10, 2 );
@@ -93,10 +102,16 @@
93 102 );
94 103
95 104 // Add an Anti-spam menu item for Jetpack. This is handled automatically by the Admin_Menu as long as it has been initialized.
96 105 Admin_Menu::init();
97 - add_action( 'admin_enqueue_scripts', array( $this, 'akismet_logo_replacement_styles' ) );
98 106 }
107 +
108 + // Render the unified Jetpack header/footer chrome on Akismet's admin pages by
109 + // consuming Akismet's `akismet_header` / `akismet_footer` action hooks. This does
110 + // not modify the Akismet plugin; it only registers callbacks on its own hooks.
111 + require_once JETPACK__PLUGIN_DIR . '_inc/lib/admin-pages/class-akismet-admin-chrome.php';
112 + $akismet_admin_chrome = new Akismet_Admin_Chrome();
113 + $akismet_admin_chrome->init_hooks();
99 114 }
100 115
101 116 // Ensure an Additional CSS menu item is added to the Appearance menu whenever Jetpack is connected.
102 117 add_action( 'admin_menu', array( $this, 'additional_css_menu' ) );
@@ -104,19 +119,19 @@
104 119 add_filter( 'jetpack_display_jitms_on_screen', array( $this, 'should_display_jitms_on_screen' ), 10, 2 );
105 120
106 121 // Register Jetpack partner coupon hooks.
107 122 Jetpack_Partner_Coupon::register_coupon_admin_hooks( 'jetpack', Jetpack::admin_url() );
108 - }
109 123
110 - /**
111 - * Generate styles to replace Akismet logo for the Jetpack Akismet Anti-spam logo.
112 - Without this, we would have to change the logo from Akismet codebase and we want to avoid that.
113 - */
114 - public function akismet_logo_replacement_styles() {
115 - $logo_url = esc_url( plugins_url( 'images/products/logo-anti-spam.svg', JETPACK__PLUGIN_FILE ) );
116 - $style = ".akismet-masthead__logo-container { background: url({$logo_url}) no-repeat; min-height: 42px; margin: 20px 0; padding: 0 !important; } .akismet-masthead__logo { display: none; }";
117 - $style .= '@media screen and (max-width: 782px) { .akismet-masthead__logo-container { margin-left: 4px; } }';
118 - wp_add_inline_style( 'admin-bar', $style );
124 + // Remove default WordPress admin footer on Jetpack pages only.
125 + add_filter( 'admin_footer_text', array( $this, 'maybe_remove_admin_footer_text' ) );
126 + add_filter( 'update_footer', array( $this, 'maybe_remove_admin_footer_version' ), 11 );
127 + add_filter( 'admin_body_class', array( $this, 'add_jetpack_admin_body_class' ) );
128 + add_action( 'admin_head', array( $this, 'add_footer_removal_styles' ) );
129 +
130 + // Make WPDS design tokens resolve at runtime on the legacy/wrap_ui Jetpack
131 + // admin pages (Dashboard, Settings, Debugger) that don't ship their own
132 + // `:root{--wpds-*}` source. Delegates to Admin_Menu's shared enqueue API.
133 + add_action( 'admin_enqueue_scripts', array( $this, 'maybe_enqueue_design_tokens' ) );
119 134 }
120 135
121 136 /**
122 137 * Handle our Additional CSS menu item and legacy page declaration.
@@ -138,9 +153,14 @@
138 153 // If the site is a WoA site and the custom-css feature is not available, return.
139 154 // See https://github.com/Automattic/jetpack/pull/19965 for more on how this menu item is dealt with on WoA sites.
140 155 if ( ( new Host() )->is_woa_site() && ! ( in_array( 'custom-css', Jetpack::get_available_modules(), true ) ) ) {
141 156 return;
142 - } elseif ( class_exists( 'Jetpack' ) && Jetpack::is_module_active( 'custom-css' ) ) { // If the Custom CSS module is enabled, add the Additional CSS menu item and link to the Customizer.
157 + } elseif (
158 + class_exists( 'Jetpack' ) && (
159 + Jetpack::is_module_active( 'custom-css' ) || // If the Custom CSS module is enabled, add the Additional CSS menu item and link to the Customizer.
160 + ( wp_is_block_theme() && ! empty( wp_get_custom_css() ) ) // Do the same if the theme is block-based but has existing custom CSS.
161 + )
162 + ) {
143 163 // Add in our legacy page to support old bookmarks and such.
144 164 add_submenu_page( '', __( 'CSS', 'jetpack' ), __( 'Additional CSS', 'jetpack' ), 'edit_theme_options', 'editcss', array( __CLASS__, 'customizer_redirect' ) );
145 165
146 166 // Add in our new page slug that will redirect to the customizer.
@@ -145,13 +165,8 @@
145 165
146 166 // Add in our new page slug that will redirect to the customizer.
147 167 $hook = add_theme_page( __( 'CSS', 'jetpack' ), __( 'Additional CSS', 'jetpack' ), 'edit_theme_options', 'editcss-customizer-redirect', array( __CLASS__, 'customizer_redirect' ) );
148 168 add_action( "load-{$hook}", array( __CLASS__, 'customizer_redirect' ) );
149 - } elseif ( class_exists( 'Jetpack' ) && Jetpack::is_connection_ready() ) { // Link to the Jetpack Settings > Writing page, highlighting the Custom CSS setting.
150 - add_submenu_page( '', __( 'CSS', 'jetpack' ), __( 'Additional CSS', 'jetpack' ), 'edit_theme_options', 'editcss', array( __CLASS__, 'theme_enhancements_redirect' ) );
151 -
152 - $hook = add_theme_page( __( 'CSS', 'jetpack' ), __( 'Additional CSS', 'jetpack' ), 'edit_theme_options', 'editcss-theme-enhancements-redirect', array( __CLASS__, 'theme_enhancements_redirect' ) );
153 - add_action( "load-{$hook}", array( __CLASS__, 'theme_enhancements_redirect' ) );
154 169 }
155 170 }
156 171
157 172 /**
@@ -173,26 +188,12 @@
173 188 'return_url' => wp_get_referer(),
174 189 )
175 190 )
176 191 );
177 - exit;
192 + exit( 0 );
178 193 }
179 194
180 195 /**
181 - * Handle the Additional CSS redirect to the Jetpack settings Theme Enhancements section.
182 - *
183 - * @since 11.0
184 - *
185 - * @return never
186 - */
187 - public static function theme_enhancements_redirect() {
188 - wp_safe_redirect(
189 - 'admin.php?page=jetpack#/writing?term=custom-css'
190 - );
191 - exit;
192 - }
193 -
194 - /**
195 196 * Build the URL to deep link to the Customizer.
196 197 *
197 198 * You can modify the return url via $args.
198 199 *
@@ -324,9 +325,9 @@
324 325 * add_filter( 'jetpack_search_terms_$module', 'jetpack_$module_search_terms' );
325 326 *
326 327 * @since 3.5.0
327 328 *
328 - * @param string The search terms (comma separated).
329 + * @param string The search terms (comma-separated).
329 330 */
330 331 echo apply_filters( 'jetpack_search_terms_' . $module, $module_array['additional_search_queries'] ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
331 332 $module_array['search_terms'] = ob_get_clean();
332 333
@@ -457,9 +458,9 @@
457 458 * level connection should be unavailable.
458 459 */
459 460 if ( ( new Status() )->is_offline_mode() ) {
460 461 if ( $module['requires_connection'] || $module['requires_user_connection'] ) {
461 - return __( 'Offline mode', 'jetpack' );
462 + return __( 'Unavailable in Offline mode', 'jetpack' );
462 463 }
463 464 }
464 465
465 466 /*
@@ -505,9 +506,9 @@
505 506 Jetpack::activate_module( $module, false );
506 507 }
507 508 // The following two lines will rarely happen, as Jetpack::activate_module normally exits at the end.
508 509 wp_safe_redirect( wp_get_referer() );
509 - exit;
510 + exit( 0 );
510 511 case 'bulk-deactivate':
511 512 check_admin_referer( 'bulk-jetpack_page_jetpack_modules' );
512 513 if ( ! current_user_can( 'jetpack_deactivate_modules' ) ) {
513 514 break;
@@ -520,9 +521,9 @@
520 521 Jetpack::state( 'message', 'module_deactivated' );
521 522 }
522 523 Jetpack::state( 'module', $modules );
523 524 wp_safe_redirect( wp_get_referer() );
524 - exit;
525 + exit( 0 );
525 526 default:
526 527 return;
527 528 }
528 529 }
@@ -569,9 +570,15 @@
569 570 nocache_headers();
570 571 if ( ! current_user_can( 'manage_options' ) ) {
571 572 die( '-1' );
572 573 }
573 - Jetpack_Admin_Page::wrap_ui( array( $this, 'debugger_page' ), array( 'is-wide' => true ) );
574 + Jetpack_Admin_Page::wrap_ui(
575 + array( $this, 'debugger_page' ),
576 + array(
577 + 'is-wide' => true,
578 + 'show-nav' => false,
579 + )
580 + );
574 581 }
575 582
576 583 /**
577 584 * Display debugger page.
@@ -603,7 +610,110 @@
603 610 return false;
604 611 }
605 612
606 613 return $value;
614 + }
615 +
616 + /**
617 + * Check if we're on a Jetpack admin page.
618 + *
619 + * Similar to how WooCommerce checks for its admin pages by comparing
620 + * against known screen ID patterns.
621 + *
622 + * @return bool True if on a Jetpack admin page, false otherwise.
623 + */
624 + private function is_jetpack_admin_page() {
625 + $screen = get_current_screen();
626 + if ( ! $screen ) {
627 + return false;
628 + }
629 +
630 + // Check for Jetpack admin pages:
631 + // - toplevel_page_jetpack (main Jetpack menu page)
632 + // - toplevel_page_jetpack-network (Jetpack Network Admin menu page)
633 + // - jetpack_page_* (Jetpack submenu pages)
634 + // - admin_page_jetpack* (legacy/special Jetpack pages)
635 + // Or check if parent_base is 'jetpack' or 'jetpack-network' (submenu pages)
636 + return (
637 + $screen->id === 'toplevel_page_jetpack' ||
638 + $screen->id === 'toplevel_page_jetpack-network' ||
639 + str_starts_with( $screen->id, 'jetpack_page_' ) ||
640 + str_starts_with( $screen->id, 'admin_page_jetpack' ) ||
641 + $screen->parent_base === 'jetpack' ||
642 + $screen->parent_base === 'jetpack-network'
643 + );
644 + }
645 +
646 + /**
647 + * Add a body class to Jetpack admin pages.
648 + *
649 + * @param string $classes Space-separated list of CSS classes.
650 + * @return string Modified class list.
651 + */
652 + public function add_jetpack_admin_body_class( $classes ) {
653 + if ( $this->is_jetpack_admin_page() ) {
654 + return ltrim( trim( $classes ) . ' jetpack-admin-page ' );
655 + }
656 + return $classes;
657 + }
658 +
659 + /**
660 + * Add inline styles to remove footer padding on Jetpack pages.
661 + *
662 + * This needs to be inline because jetpack-admin.css is not loaded on
663 + * React-powered admin pages (they use load_wrapper_styles instead).
664 + */
665 + public function add_footer_removal_styles() {
666 + if ( ! $this->is_jetpack_admin_page() ) {
667 + return;
668 + }
669 + echo '<style>.jetpack-admin-page #wpbody-content { padding-bottom: 0; } .jetpack-admin-page #wpfooter { display: none; }</style>';
670 + }
671 +
672 + /**
673 + * Enqueues the shared WPDS design-tokens stylesheet on the legacy/wrap_ui pages.
674 + *
675 + * This is the admin_enqueue_scripts callback for the legacy Jetpack admin
676 + * pages. The admin-ui package owns the handle and enqueues it on the
677 + * modernized dashboards it registers; the legacy/wrap_ui pages (Dashboard,
678 + * Settings, Debugger) aren't registered through Admin_Menu, so we cover them
679 + * here via the central is_jetpack_admin_page() gate. The actual enqueue is
680 + * delegated to the reusable Admin_Menu::enqueue_design_tokens() API so there
681 + * is a single owner of the handle and no duplicated register/enqueue logic.
682 + *
683 + * @return void
684 + */
685 + public function maybe_enqueue_design_tokens() {
686 + if ( ! $this->is_jetpack_admin_page() ) {
687 + return;
688 + }
689 +
690 + // Guard against an older admin-ui being loaded ahead of this one by the
691 + // package autoloader's version-precedence resolution.
692 + if ( ! method_exists( Admin_Menu::class, 'enqueue_design_tokens' ) ) {
693 + return;
694 + }
695 +
696 + Admin_Menu::enqueue_design_tokens();
697 + }
698 +
699 + /**
700 + * Remove the admin footer text on Jetpack pages.
701 + *
702 + * @param string $content The default footer text.
703 + * @return string Empty string on Jetpack pages, original content otherwise.
704 + */
705 + public function maybe_remove_admin_footer_text( $content ) {
706 + return $this->is_jetpack_admin_page() ? '' : $content;
707 + }
708 +
709 + /**
710 + * Remove the admin footer version on Jetpack pages.
711 + *
712 + * @param string $content The default footer version text.
713 + * @return string Empty string on Jetpack pages, original content otherwise.
714 + */
715 + public function maybe_remove_admin_footer_version( $content ) {
716 + return $this->is_jetpack_admin_page() ? '' : $content;
607 717 }
608 718 }
609 719 Jetpack_Admin::init();