From 446f4dbf87c65a59b198f6bc32aefca505fbe265 Mon Sep 17 00:00:00 2001 From: Tony Arcangelini Date: Thu, 7 May 2026 12:36:08 +0200 Subject: [PATCH 1/8] Podcast: simplify wp-build wiring and fix menu reorder slug --- pnpm-lock.yaml | 3 - .../arcangelini-podcast-make-it-better | 5 + .../wpcom-admin-menu/wpcom-admin-menu.php | 3 +- .../arcangelini-podcast-make-it-better | 4 + projects/packages/podcast/package.json | 1 - .../packages/podcast/src/class-admin-page.php | 202 ++++++------------ 6 files changed, 77 insertions(+), 141 deletions(-) create mode 100644 projects/packages/jetpack-mu-wpcom/changelog/arcangelini-podcast-make-it-better create mode 100644 projects/packages/podcast/changelog/arcangelini-podcast-make-it-better diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index bd08d9459f7..091306f776d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -3629,9 +3629,6 @@ importers: specifier: 0.11.0 version: 0.11.0(@types/react@18.3.28)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) devDependencies: - '@automattic/jetpack-wp-build-polyfills': - specifier: workspace:* - version: link:../wp-build-polyfills '@babel/core': specifier: 7.29.0 version: 7.29.0 diff --git a/projects/packages/jetpack-mu-wpcom/changelog/arcangelini-podcast-make-it-better b/projects/packages/jetpack-mu-wpcom/changelog/arcangelini-podcast-make-it-better new file mode 100644 index 00000000000..5c64c6e6687 --- /dev/null +++ b/projects/packages/jetpack-mu-wpcom/changelog/arcangelini-podcast-make-it-better @@ -0,0 +1,5 @@ +Significance: patch +Type: changed +Comment: Internal: collapse the Podcast slug to a single 'podcast' entry in the Jetpack submenu reorder list. + + diff --git a/projects/packages/jetpack-mu-wpcom/src/features/wpcom-admin-menu/wpcom-admin-menu.php b/projects/packages/jetpack-mu-wpcom/src/features/wpcom-admin-menu/wpcom-admin-menu.php index 38aad8eab7d..911a8239f87 100644 --- a/projects/packages/jetpack-mu-wpcom/src/features/wpcom-admin-menu/wpcom-admin-menu.php +++ b/projects/packages/jetpack-mu-wpcom/src/features/wpcom-admin-menu/wpcom-admin-menu.php @@ -466,8 +466,7 @@ function () { 'search', 'subscribers', 'newsletter', - 'jetpack-podcast', - 'podcasting', + 'podcast', 'traffic', 'jetpack#/settings', ) diff --git a/projects/packages/podcast/changelog/arcangelini-podcast-make-it-better b/projects/packages/podcast/changelog/arcangelini-podcast-make-it-better new file mode 100644 index 00000000000..d23e3f2f3e5 --- /dev/null +++ b/projects/packages/podcast/changelog/arcangelini-podcast-make-it-better @@ -0,0 +1,4 @@ +Significance: patch +Type: changed + +Slim down wp-build wiring to the Backup pattern: drop bridge_wp_build_enqueue and fix_boot_import_map_ordering, alias $screen->id via current_screen instead. diff --git a/projects/packages/podcast/package.json b/projects/packages/podcast/package.json index f3eeedc12ad..5287c89b130 100644 --- a/projects/packages/podcast/package.json +++ b/projects/packages/podcast/package.json @@ -33,7 +33,6 @@ "@wordpress/ui": "0.11.0" }, "devDependencies": { - "@automattic/jetpack-wp-build-polyfills": "workspace:*", "@babel/core": "7.29.0", "@babel/runtime": "7.29.2", "@types/react": "18.3.28", diff --git a/projects/packages/podcast/src/class-admin-page.php b/projects/packages/podcast/src/class-admin-page.php index 4aa92d26859..1f8da6a33bf 100644 --- a/projects/packages/podcast/src/class-admin-page.php +++ b/projects/packages/podcast/src/class-admin-page.php @@ -22,9 +22,9 @@ * registration path covers both. Standalone Jetpack is excluded by the host * gate in `Podcast::init()`. * - * The wp-build chassis is loaded inline from `init()` and routed onto our - * user-facing slug via `bridge_wp_build_enqueue()` — mirroring - * `Automattic\Jetpack\Scan_Page\Jetpack_Scan`. + * Mirrors `Automattic\Jetpack\Backup\V0005\Jetpack_Backup` — wp-build's + * polyfills + auto-generated render/enqueue functions do the heavy lifting; + * we just alias `$screen->id` so the auto-enqueue check passes for our slug. */ class Admin_Page { @@ -36,13 +36,14 @@ class Admin_Page { const ADMIN_PAGE_SLUG = 'jetpack-podcast'; /** - * Internal slug emitted by `@wordpress/build` (`wpPlugin.pages[0]` - * plus the `-wp-admin` suffix the build template appends). Used to - * find the auto-generated render / enqueue functions. + * wp-build page slug emitted by `@wordpress/build` (`wpPlugin.pages[0]`). + * The auto-generated enqueue callback only fires when `$screen->id` + * matches this value, so we alias the screen id via `current_screen` + * on our admin page without changing the user-facing slug. * * @var string */ - const WP_BUILD_SLUG = 'jetpack-podcast-dashboard-wp-admin'; + const WP_BUILD_SLUG = 'jetpack-podcast-dashboard'; /** * Whether the class has already wired its admin hooks. @@ -54,13 +55,6 @@ class Admin_Page { /** * Wire the admin hooks. Called from `Podcast::init()` once the * `jetpack_podcast_untangle` filter and host gates have been satisfied. - * - * Menu registration itself is handled by `wpcom-admin-menu.php` calling - * `add_wp_admin_submenu()` at `admin_menu` priority 999999. Here we set - * up the wp-build chassis at plugins_loaded time so: - * - `WP_Build_Polyfills::register()` registers BEFORE `wp_default_scripts` - * fires (otherwise `@wordpress/boot` never lands in the import map). - * - The wp-build render function is defined before the menu callback runs. */ public static function init() { if ( self::$initialized ) { @@ -68,9 +62,7 @@ public static function init() { } self::$initialized = true; - self::load_wp_build(); - self::bridge_wp_build_enqueue(); - self::fix_boot_import_map_ordering(); + add_action( 'admin_menu', array( __CLASS__, 'maybe_load_wp_build' ), 1 ); } /** @@ -85,6 +77,11 @@ public static function add_wp_admin_submenu() { return; } + $wp_build_render = 'jetpack_podcast_jetpack_podcast_dashboard_wp_admin_render_page'; + $callback = function_exists( $wp_build_render ) + ? $wp_build_render + : array( __CLASS__, 'render' ); + $page_suffix = add_submenu_page( 'jetpack', /** "Podcast" is a product name, do not translate. */ @@ -92,7 +89,7 @@ public static function add_wp_admin_submenu() { 'Podcast', 'manage_options', self::ADMIN_PAGE_SLUG, - self::get_render_callback() + $callback ); if ( $page_suffix ) { @@ -104,127 +101,67 @@ public static function add_wp_admin_submenu() { * Wire admin-init actions once we know the Podcast page is loading. * * Subsequent PRs in the untangle train layer script-data + Tracks here. - * The wp-build dashboard manages its own enqueue pipeline (bridged via - * `bridge_wp_build_enqueue()`). + * The wp-build dashboard manages its own enqueue pipeline. */ public static function admin_init() { // Intentionally empty for now. } /** - * Bridge wp-build's auto-generated enqueue function — which checks for - * `?page=jetpack-podcast-dashboard-wp-admin` — to our user-facing slug - * `?page=jetpack-podcast`. Hooked at priority 9 so the wp-build copy - * (registered at priority 10) sees the original `$_GET['page']` and skips - * its own enqueue. + * Load wp-build only on the Podcast admin page, then alias `$screen->id` + * so wp-build's auto-generated enqueue callback fires for our slug. + * + * Hooked at admin_menu priority 1 so polyfills register before + * `wp_default_scripts` fires and the wp-build render function is defined + * before `add_wp_admin_submenu()` runs at priority 999999. * - * Mirrors `Automattic\Jetpack\Scan_Page\Jetpack_Scan::bridge_wp_build_enqueue`. + * Mirrors `Automattic\Jetpack\Backup\V0005\Jetpack_Backup::maybe_load_wp_build`. */ - private static function bridge_wp_build_enqueue() { - add_action( - 'admin_enqueue_scripts', - static function ( $hook_suffix ) { - // phpcs:ignore WordPress.Security.NonceVerification.Recommended - if ( ! isset( $_GET['page'] ) || self::ADMIN_PAGE_SLUG !== $_GET['page'] ) { - return; - } - - $enqueue_fn = 'jetpack_podcast_jetpack_podcast_dashboard_wp_admin_enqueue_scripts'; - if ( ! function_exists( $enqueue_fn ) ) { - return; - } + public static function maybe_load_wp_build() { + if ( ! self::is_enabled() || ! self::is_podcast_admin_request() ) { + return; + } - // phpcs:disable WordPress.Security.NonceVerification.Recommended,WordPress.Security.ValidatedSanitizedInput.MissingUnslash,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized - $original = isset( $_GET['page'] ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : null; - $_GET['page'] = self::WP_BUILD_SLUG; - // @phan-suppress-next-line PhanUndeclaredFunctionInCallable -- Function is generated by @wordpress/build into build/pages/jetpack-podcast-dashboard/page-wp-admin.php, which is outside Phan's analysis scope. The function_exists() guard above protects the call at runtime. - call_user_func( $enqueue_fn, $hook_suffix ); - if ( null === $original ) { - unset( $_GET['page'] ); - } else { - $_GET['page'] = $original; - } - // phpcs:enable WordPress.Security.NonceVerification.Recommended,WordPress.Security.ValidatedSanitizedInput.MissingUnslash,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized - }, - 9 - ); + self::load_wp_build(); + add_action( 'current_screen', array( __CLASS__, 'alias_screen_id_for_wp_build' ) ); } /** - * Fix import map ordering for the wp-build boot script. - * - * In wp-admin, `_wp_footer_scripts` (classic scripts) and - * `print_import_map` both hook into `admin_print_footer_scripts` at - * priority 10, but `_wp_footer_scripts` is registered first. This causes - * the inline `import("@wordpress/boot")` to execute before the import - * map exists. - * - * This fix moves the `import()` call from the classic inline script to a - * `