| @@ -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 | |
| @@ -61,15 +62,19 @@ | ||
| 61 | 62 | |
| 62 | 63 | require_once JETPACK__PLUGIN_DIR . '_inc/lib/admin-pages/class-jetpack-about-page.php'; |
| 63 | 64 | $jetpack_about = new Jetpack_About_Page(); |
| 64 | 65 | |
| 66 | + require_once JETPACK__PLUGIN_DIR . '_inc/lib/admin-pages/class-jetpack-ai-page.php'; | |
| 67 | + $jetpack_ai = new Jetpack_AI_Page(); | |
| 68 | + | |
| 65 | 69 | add_action( 'admin_init', array( $jetpack_react, 'react_redirects' ), 0 ); |
| 66 | 70 | 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' ) ); | |
| 71 | + add_action( 'admin_menu', array( $jetpack_react, 'remove_jetpack_menu' ), 2000 ); | |
| 68 | 72 | add_action( 'jetpack_admin_menu', array( $jetpack_react, 'jetpack_add_settings_sub_nav_item' ) ); |
| 69 | 73 | add_action( 'jetpack_admin_menu', array( $this, 'admin_menu_debugger' ) ); |
| 70 | 74 | add_action( 'jetpack_admin_menu', array( $fallback_page, 'add_actions' ) ); |
| 71 | 75 | add_action( 'jetpack_admin_menu', array( $jetpack_about, 'add_actions' ) ); |
| 76 | + add_action( 'jetpack_admin_menu', array( $jetpack_ai, 'add_actions' ) ); | |
| 72 | 77 | |
| 73 | 78 | // Add redirect to current page for activation/deactivation of modules. |
| 74 | 79 | add_action( 'jetpack_pre_activate_module', array( $this, 'fix_redirect' ), 10, 2 ); |
| 75 | 80 | add_action( 'jetpack_pre_deactivate_module', array( $this, 'fix_redirect' ), 10, 2 ); |
| @@ -93,10 +98,16 @@ | ||
| 93 | 98 | ); |
| 94 | 99 | |
| 95 | 100 | // Add an Anti-spam menu item for Jetpack. This is handled automatically by the Admin_Menu as long as it has been initialized. |
| 96 | 101 | Admin_Menu::init(); |
| 97 | - add_action( 'admin_enqueue_scripts', array( $this, 'akismet_logo_replacement_styles' ) ); | |
| 98 | 102 | } |
| 103 | + | |
| 104 | + // Render the unified Jetpack header/footer chrome on Akismet's admin pages by | |
| 105 | + // consuming Akismet's `akismet_header` / `akismet_footer` action hooks. This does | |
| 106 | + // not modify the Akismet plugin; it only registers callbacks on its own hooks. | |
| 107 | + require_once JETPACK__PLUGIN_DIR . '_inc/lib/admin-pages/class-akismet-admin-chrome.php'; | |
| 108 | + $akismet_admin_chrome = new Akismet_Admin_Chrome(); | |
| 109 | + $akismet_admin_chrome->init_hooks(); | |
| 99 | 110 | } |
| 100 | 111 | |
| 101 | 112 | // Ensure an Additional CSS menu item is added to the Appearance menu whenever Jetpack is connected. |
| 102 | 113 | add_action( 'admin_menu', array( $this, 'additional_css_menu' ) ); |
| @@ -104,19 +115,19 @@ | ||
| 104 | 115 | add_filter( 'jetpack_display_jitms_on_screen', array( $this, 'should_display_jitms_on_screen' ), 10, 2 ); |
| 105 | 116 | |
| 106 | 117 | // Register Jetpack partner coupon hooks. |
| 107 | 118 | Jetpack_Partner_Coupon::register_coupon_admin_hooks( 'jetpack', Jetpack::admin_url() ); |
| 108 | - } | |
| 109 | 119 | |
| 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 ); | |
| 120 | + // Remove default WordPress admin footer on Jetpack pages only. | |
| 121 | + add_filter( 'admin_footer_text', array( $this, 'maybe_remove_admin_footer_text' ) ); | |
| 122 | + add_filter( 'update_footer', array( $this, 'maybe_remove_admin_footer_version' ), 11 ); | |
| 123 | + add_filter( 'admin_body_class', array( $this, 'add_jetpack_admin_body_class' ) ); | |
| 124 | + add_action( 'admin_head', array( $this, 'add_footer_removal_styles' ) ); | |
| 125 | + | |
| 126 | + // Make WPDS design tokens resolve at runtime on the legacy/wrap_ui Jetpack | |
| 127 | + // admin pages (Dashboard, Settings, Debugger) that don't ship their own | |
| 128 | + // `:root{--wpds-*}` source. Delegates to Admin_Menu's shared enqueue API. | |
| 129 | + add_action( 'admin_enqueue_scripts', array( $this, 'maybe_enqueue_design_tokens' ) ); | |
| 119 | 130 | } |
| 120 | 131 | |
| 121 | 132 | /** |
| 122 | 133 | * Handle our Additional CSS menu item and legacy page declaration. |
| @@ -150,13 +161,8 @@ | ||
| 150 | 161 | |
| 151 | 162 | // Add in our new page slug that will redirect to the customizer. |
| 152 | 163 | $hook = add_theme_page( __( 'CSS', 'jetpack' ), __( 'Additional CSS', 'jetpack' ), 'edit_theme_options', 'editcss-customizer-redirect', array( __CLASS__, 'customizer_redirect' ) ); |
| 153 | 164 | add_action( "load-{$hook}", array( __CLASS__, 'customizer_redirect' ) ); |
| 154 | - } elseif ( class_exists( 'Jetpack' ) && Jetpack::is_connection_ready() ) { // Link to the Jetpack Settings > Writing page, highlighting the Custom CSS setting. | |
| 155 | - add_submenu_page( '', __( 'CSS', 'jetpack' ), __( 'Additional CSS', 'jetpack' ), 'edit_theme_options', 'editcss', array( __CLASS__, 'theme_enhancements_redirect' ) ); | |
| 156 | - | |
| 157 | - $hook = add_theme_page( __( 'CSS', 'jetpack' ), __( 'Additional CSS', 'jetpack' ), 'edit_theme_options', 'editcss-theme-enhancements-redirect', array( __CLASS__, 'theme_enhancements_redirect' ) ); | |
| 158 | - add_action( "load-{$hook}", array( __CLASS__, 'theme_enhancements_redirect' ) ); | |
| 159 | 165 | } |
| 160 | 166 | } |
| 161 | 167 | |
| 162 | 168 | /** |
| @@ -178,26 +184,12 @@ | ||
| 178 | 184 | 'return_url' => wp_get_referer(), |
| 179 | 185 | ) |
| 180 | 186 | ) |
| 181 | 187 | ); |
| 182 | - exit; | |
| 188 | + exit( 0 ); | |
| 183 | 189 | } |
| 184 | 190 | |
| 185 | 191 | /** |
| 186 | - * Handle the Additional CSS redirect to the Jetpack settings Theme Enhancements section. | |
| 187 | - * | |
| 188 | - * @since 11.0 | |
| 189 | - * | |
| 190 | - * @return never | |
| 191 | - */ | |
| 192 | - public static function theme_enhancements_redirect() { | |
| 193 | - wp_safe_redirect( | |
| 194 | - 'admin.php?page=jetpack#/writing?term=custom-css' | |
| 195 | - ); | |
| 196 | - exit; | |
| 197 | - } | |
| 198 | - | |
| 199 | - /** | |
| 200 | 192 | * Build the URL to deep link to the Customizer. |
| 201 | 193 | * |
| 202 | 194 | * You can modify the return url via $args. |
| 203 | 195 | * |
| @@ -329,9 +321,9 @@ | ||
| 329 | 321 | * add_filter( 'jetpack_search_terms_$module', 'jetpack_$module_search_terms' ); |
| 330 | 322 | * |
| 331 | 323 | * @since 3.5.0 |
| 332 | 324 | * |
| 333 | - * @param string The search terms (comma separated). | |
| 325 | + * @param string The search terms (comma-separated). | |
| 334 | 326 | */ |
| 335 | 327 | echo apply_filters( 'jetpack_search_terms_' . $module, $module_array['additional_search_queries'] ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 336 | 328 | $module_array['search_terms'] = ob_get_clean(); |
| 337 | 329 | |
| @@ -462,9 +454,9 @@ | ||
| 462 | 454 | * level connection should be unavailable. |
| 463 | 455 | */ |
| 464 | 456 | if ( ( new Status() )->is_offline_mode() ) { |
| 465 | 457 | if ( $module['requires_connection'] || $module['requires_user_connection'] ) { |
| 466 | - return __( 'Offline mode', 'jetpack' ); | |
| 458 | + return __( 'Unavailable in Offline mode', 'jetpack' ); | |
| 467 | 459 | } |
| 468 | 460 | } |
| 469 | 461 | |
| 470 | 462 | /* |
| @@ -510,9 +502,9 @@ | ||
| 510 | 502 | Jetpack::activate_module( $module, false ); |
| 511 | 503 | } |
| 512 | 504 | // The following two lines will rarely happen, as Jetpack::activate_module normally exits at the end. |
| 513 | 505 | wp_safe_redirect( wp_get_referer() ); |
| 514 | - exit; | |
| 506 | + exit( 0 ); | |
| 515 | 507 | case 'bulk-deactivate': |
| 516 | 508 | check_admin_referer( 'bulk-jetpack_page_jetpack_modules' ); |
| 517 | 509 | if ( ! current_user_can( 'jetpack_deactivate_modules' ) ) { |
| 518 | 510 | break; |
| @@ -525,9 +517,9 @@ | ||
| 525 | 517 | Jetpack::state( 'message', 'module_deactivated' ); |
| 526 | 518 | } |
| 527 | 519 | Jetpack::state( 'module', $modules ); |
| 528 | 520 | wp_safe_redirect( wp_get_referer() ); |
| 529 | - exit; | |
| 521 | + exit( 0 ); | |
| 530 | 522 | default: |
| 531 | 523 | return; |
| 532 | 524 | } |
| 533 | 525 | } |
| @@ -574,9 +566,15 @@ | ||
| 574 | 566 | nocache_headers(); |
| 575 | 567 | if ( ! current_user_can( 'manage_options' ) ) { |
| 576 | 568 | die( '-1' ); |
| 577 | 569 | } |
| 578 | - Jetpack_Admin_Page::wrap_ui( array( $this, 'debugger_page' ), array( 'is-wide' => true ) ); | |
| 570 | + Jetpack_Admin_Page::wrap_ui( | |
| 571 | + array( $this, 'debugger_page' ), | |
| 572 | + array( | |
| 573 | + 'is-wide' => true, | |
| 574 | + 'show-nav' => false, | |
| 575 | + ) | |
| 576 | + ); | |
| 579 | 577 | } |
| 580 | 578 | |
| 581 | 579 | /** |
| 582 | 580 | * Display debugger page. |
| @@ -608,7 +606,110 @@ | ||
| 608 | 606 | return false; |
| 609 | 607 | } |
| 610 | 608 | |
| 611 | 609 | return $value; |
| 610 | + } | |
| 611 | + | |
| 612 | + /** | |
| 613 | + * Check if we're on a Jetpack admin page. | |
| 614 | + * | |
| 615 | + * Similar to how WooCommerce checks for its admin pages by comparing | |
| 616 | + * against known screen ID patterns. | |
| 617 | + * | |
| 618 | + * @return bool True if on a Jetpack admin page, false otherwise. | |
| 619 | + */ | |
| 620 | + private function is_jetpack_admin_page() { | |
| 621 | + $screen = get_current_screen(); | |
| 622 | + if ( ! $screen ) { | |
| 623 | + return false; | |
| 624 | + } | |
| 625 | + | |
| 626 | + // Check for Jetpack admin pages: | |
| 627 | + // - toplevel_page_jetpack (main Jetpack menu page) | |
| 628 | + // - toplevel_page_jetpack-network (Jetpack Network Admin menu page) | |
| 629 | + // - jetpack_page_* (Jetpack submenu pages) | |
| 630 | + // - admin_page_jetpack* (legacy/special Jetpack pages) | |
| 631 | + // Or check if parent_base is 'jetpack' or 'jetpack-network' (submenu pages) | |
| 632 | + return ( | |
| 633 | + $screen->id === 'toplevel_page_jetpack' || | |
| 634 | + $screen->id === 'toplevel_page_jetpack-network' || | |
| 635 | + str_starts_with( $screen->id, 'jetpack_page_' ) || | |
| 636 | + str_starts_with( $screen->id, 'admin_page_jetpack' ) || | |
| 637 | + $screen->parent_base === 'jetpack' || | |
| 638 | + $screen->parent_base === 'jetpack-network' | |
| 639 | + ); | |
| 640 | + } | |
| 641 | + | |
| 642 | + /** | |
| 643 | + * Add a body class to Jetpack admin pages. | |
| 644 | + * | |
| 645 | + * @param string $classes Space-separated list of CSS classes. | |
| 646 | + * @return string Modified class list. | |
| 647 | + */ | |
| 648 | + public function add_jetpack_admin_body_class( $classes ) { | |
| 649 | + if ( $this->is_jetpack_admin_page() ) { | |
| 650 | + return ltrim( trim( $classes ) . ' jetpack-admin-page ' ); | |
| 651 | + } | |
| 652 | + return $classes; | |
| 653 | + } | |
| 654 | + | |
| 655 | + /** | |
| 656 | + * Add inline styles to remove footer padding on Jetpack pages. | |
| 657 | + * | |
| 658 | + * This needs to be inline because jetpack-admin.css is not loaded on | |
| 659 | + * React-powered admin pages (they use load_wrapper_styles instead). | |
| 660 | + */ | |
| 661 | + public function add_footer_removal_styles() { | |
| 662 | + if ( ! $this->is_jetpack_admin_page() ) { | |
| 663 | + return; | |
| 664 | + } | |
| 665 | + echo '<style>.jetpack-admin-page #wpbody-content { padding-bottom: 0; } .jetpack-admin-page #wpfooter { display: none; }</style>'; | |
| 666 | + } | |
| 667 | + | |
| 668 | + /** | |
| 669 | + * Enqueues the shared WPDS design-tokens stylesheet on the legacy/wrap_ui pages. | |
| 670 | + * | |
| 671 | + * This is the admin_enqueue_scripts callback for the legacy Jetpack admin | |
| 672 | + * pages. The admin-ui package owns the handle and enqueues it on the | |
| 673 | + * modernized dashboards it registers; the legacy/wrap_ui pages (Dashboard, | |
| 674 | + * Settings, Debugger) aren't registered through Admin_Menu, so we cover them | |
| 675 | + * here via the central is_jetpack_admin_page() gate. The actual enqueue is | |
| 676 | + * delegated to the reusable Admin_Menu::enqueue_design_tokens() API so there | |
| 677 | + * is a single owner of the handle and no duplicated register/enqueue logic. | |
| 678 | + * | |
| 679 | + * @return void | |
| 680 | + */ | |
| 681 | + public function maybe_enqueue_design_tokens() { | |
| 682 | + if ( ! $this->is_jetpack_admin_page() ) { | |
| 683 | + return; | |
| 684 | + } | |
| 685 | + | |
| 686 | + // Guard against an older admin-ui being loaded ahead of this one by the | |
| 687 | + // package autoloader's version-precedence resolution. | |
| 688 | + if ( ! method_exists( Admin_Menu::class, 'enqueue_design_tokens' ) ) { | |
| 689 | + return; | |
| 690 | + } | |
| 691 | + | |
| 692 | + Admin_Menu::enqueue_design_tokens(); | |
| 693 | + } | |
| 694 | + | |
| 695 | + /** | |
| 696 | + * Remove the admin footer text on Jetpack pages. | |
| 697 | + * | |
| 698 | + * @param string $content The default footer text. | |
| 699 | + * @return string Empty string on Jetpack pages, original content otherwise. | |
| 700 | + */ | |
| 701 | + public function maybe_remove_admin_footer_text( $content ) { | |
| 702 | + return $this->is_jetpack_admin_page() ? '' : $content; | |
| 703 | + } | |
| 704 | + | |
| 705 | + /** | |
| 706 | + * Remove the admin footer version on Jetpack pages. | |
| 707 | + * | |
| 708 | + * @param string $content The default footer version text. | |
| 709 | + * @return string Empty string on Jetpack pages, original content otherwise. | |
| 710 | + */ | |
| 711 | + public function maybe_remove_admin_footer_version( $content ) { | |
| 712 | + return $this->is_jetpack_admin_page() ? '' : $content; | |
| 612 | 713 | } |
| 613 | 714 | } |
| 614 | 715 | Jetpack_Admin::init(); |