Repository navigation
Admin shell: Offer to turn a switched-off feature back on when its page is opened - #55003
Conversation
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! Jetpack plugin: The Jetpack plugin has different release cadences depending on the platform:
If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. |
3650a59 to
f5032ed
Compare
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
Code Coverage SummaryCoverage changed in 9 files. Only the first 5 are listed here.
1 file is newly checked for coverage.
Full summary · PHP report · JS report Coverage check overridden by
Covered by non-unit tests
|
4556334 to
a397457
Compare
kraftbj
left a comment
There was a problem hiding this comment.
Thanks, the fail-open check and the gate nonce read well. A few things inline before this lands. Could the Back-to-a-switched-off-page case and the panel's focus also get a spec in tests/e2e/specs/admin-shell/? accessibility.test.ts already has the focus and announcement helpers.
| const hostApp = createApp( host, hostEl ); | ||
| apps.set( host, hostApp ); | ||
| const removeHostHeader = showHeaderAt( host, hostEl, location.href ); | ||
| if ( members[ host ].featureOn === false ) { |
There was a problem hiding this comment.
Two small things on the host: the whenRendered handler below still emits page-shown while the panel covers the host (onScreen( host ) instead of visible === host would fix it), and the server already knows the feature is off here, so the extra request, and the host app booting behind the card, could be skipped by sending the card with the config.
There was a problem hiding this comment.
The page-shown part is fixed (onScreen( host )), and the config now carries the host's card as featureCard, so there's no extra request. My Jetpack's filter reads a failed Turn on's error from the page URL on a page load and from the referer over admin-ajax.
I left the host boot alone. That boot is wp-build's generated inline script on DOMContentLoaded, so the shell could only stop it by failing initSinglePage() (hiding the mount element) or by dequeuing generated code. That seemed worse than one hidden boot on a page that Turn on reloads anyway. Happy to revisit if you see a clean hook for it.
a397457 to
42aeb7b
Compare
…ch the card's check to activation's
42aeb7b to
b77cca7
Compare
|
Thanks for the review. All four inline notes are addressed in 8d509a9; replies are on each thread. For the e2e request,
Both pass in Chromium against the JN test site. The first one fails against the previous shell build, on the |
… let the switch place focus on the turned-off panel
8d509a9 to
3b97d04
Compare
A hybrid product reads as installed off the Jetpack plugin alone, but activating it installs its standalone plugin. Check the product's own plugin instead, so Turn on never installs one from WordPress.org.
# Conflicts: # projects/packages/admin-ui/src/admin-shell/index.js # projects/packages/admin-ui/src/class-admin-shell.php # projects/packages/admin-ui/tests/js/admin-shell/index.test.js # projects/packages/admin-ui/tests/php/Admin_Shell_Test.php # projects/packages/my-jetpack/src/class-menu-visibility.php # projects/packages/my-jetpack/src/class-turned-off-page.php # projects/packages/my-jetpack/tests/php/Menu_Visibility_Test.php # projects/packages/my-jetpack/tests/php/Turned_Off_Page_Test.php
Part of JETPACK-3799
Stacked on #55037, which adds the turned-off card for a feature's page. Review that one first; this PR's diff is only the admin shell side.
Proposed changes
With the admin shell on (behind the
jetpack-admin-shellflag), you could still open a feature you'd just switched off, because the shell kept already-loaded pages in memory, and pages that stay registered while their feature is off (Jetpack AI, Social, Search) never showed the card. This PR makes the shell check a page's feature on every visit and show My Jetpack's turned-off card in place of the page when it's off.Admin shell (
packages/admin-ui)jetpack_admin_shell_feature. Each member's gate comes from theAdmin_Menuitem it already declares.Admin_Menu::set_feature_activator( $activator, $offer_check )). Otherwise the page is left alone, and with no activator registered (an older My Jetpack) nothing is offered, so there's never a dead-end Turn on button.jetpack_admin_shell_feature_off_cardfilter. The card's own script (progress, view tracking) is re-run after it's inserted, sinceinnerHTMLleaves scripts inert. Without a card, the shell shows a plain fallback panel.My Jetpack (
packages/my-jetpack)Menu_Visibility::offers()) adds one rule to My Jetpack: Offer to turn a switched-off feature back on when its page is opened #55037'scan_offer(): only features the Features tab lists, so a page without a card, such as SEO's own "Enable SEO tools" screen, is left alone.context: admin_shellfor Tracks. After a failed Turn on the card reads the error from the page URL (the admin-ajax referer), since the card arrives over admin-ajax.<body>as an inline style (@wordpress/boot'suseSyncBodyBackground). With its app still in the page behind the card, the page would turn the menu's near-black, so the card restores wp-admin's grey while it's on the page.Activity Log (
packages/activity-log)module => activity-log, so the shell can tell when it's off. The sidebar doesn't change, because the item already disappears while the module is off.Screenshots
Live check
On a connected Jurassic Ninja site running this PR's Jetpack Beta build
16.5-a.4-44214858986-gc46c1f2a, which includes PR 55037's install-guard fix, with thejetpack-admin-shellflag set to on. The site had no standalone VideoPress plugin, and the duplicate production copy of Jetpack was deactivated.jetpack-videopress). Nothing was installed.Code coverage
The unit tests cover what the shell stands in for, the gate nonce, the check on every visit, leaving a page before its check returns, and the card's error for its own page only. The lines left uncovered are
Admin_Shell::ajax_feature(), which ends inwp_send_json_*(); the rehearsals below and the manual Back/Forward test exercise it, hence theCovered by non-unit testslabel.Related product discussion/links
Does this pull request change what data or activity we track or use?
No new events. #55037's
jetpack_myjetpack_feature_off_viewandjetpack_myjetpack_feature_off_turn_on_clickgaincontext: admin_shellwhen the card shows in the shell.Testing instructions
Turn on the
jetpack-admin-shellflag (wp companion feature-flag enable jetpack-admin-shellon Jurassic Ninja). Then run the rehearsals below from Tools → Rehearsal on a connected Jetpack site running this branch. The admin shell one needs Forms on; the Social one switches Social off in My Jetpack › Features and turns it back on from the card.Rehearsal: Admin shell: a page whose feature is on still opens without a page load
Rehearsal
855e390· 9 steps · coverspackages/my-jetpack,packages/forms,packages/admin-uiLast run: Passed on WordPress 7.1.4 · Theme: Twenty Twenty-Four 1.6 · Jetpack 16.5-a.1, run #105, 2026-11-16.
View or install this rehearsal · JSON · Playwright test (links work while sure-crawdad-pheasant.jurassic.ninja exists)
Rehearsal JSON
{ "format": 2, "requires": [ "jetpack" ], "covers": [ "packages/my-jetpack", "packages/forms", "packages/admin-ui" ], "viewport": "desktop", "timeout": 30000, "steps": [ { "goto": "/wp-admin/admin.php?page=my-jetpack&p=%2Ffeatures" }, { "expect": "script[id=\"wp-script-module-data-@automattic/jetpack-admin-shell\"]", "toHaveCount": 1 }, { "expect": "[role=switch][aria-label=\"Toggle Forms module\"]", "toBeVisible": true }, { "expect": "[role=switch][aria-label=\"Toggle Forms module\"][aria-checked=\"true\"]", "toBeVisible": true }, { "click": "#adminmenu a[href*=\"page=jetpack-forms-responses-wp-admin\"]" }, { "expect": "[data-shell-page=\"jetpack-forms-responses-wp-admin\"][data-shell-state=\"visible\"]", "toHaveCount": 1 }, { "expect": "[data-shell-page=\"my-jetpack\"]", "toHaveCount": 1 }, { "expect": ".jetpack-admin-shell-feature-off", "toHaveCount": 0 }, { "expectNoConsoleErrors": { "ignore": [ "the \"jetpack-connection\" store was already registered" ] } } ] }Rehearsal: Social: switched off in My Jetpack, the admin shell offers to turn it on and brings it back (changes the site)
Rehearsal
a083954· 14 steps · coverspackages/admin-ui,packages/my-jetpack,packages/publicizeLast run: Passed on WordPress 7.1.4 · Theme: Twenty Twenty-Four 1.6 · Jetpack 16.5-a.1, run #124, 2026-11-16.
View or install this rehearsal · JSON · Playwright test (links work while sure-crawdad-pheasant.jurassic.ninja exists)
Rehearsal JSON
{ "format": 2, "requires": [ "jetpack" ], "covers": [ "packages/admin-ui", "packages/my-jetpack", "packages/publicize" ], "viewport": "desktop", "timeout": 30000, "steps": [ { "goto": "/wp-admin/admin.php?page=my-jetpack&p=%2Ffeatures" }, { "expect": "[data-shell-page=\"my-jetpack\"]", "toHaveCount": 1 }, { "expect": "[role=switch][aria-label=\"Toggle Jetpack Social module\"]", "toBeVisible": true }, { "click": "[role=switch][aria-label=\"Toggle Jetpack Social module\"][aria-checked=\"true\"]", "optional": true, "timeout": 3000 }, { "expect": "[role=switch][aria-label=\"Toggle Jetpack Social module\"][aria-checked=\"false\"]", "toBeVisible": true }, { "expect": "#adminmenu a[href*=\"page=jetpack-social\"]", "toHaveCount": 0 }, { "goto": "/wp-admin/admin.php?page=jetpack-social" }, { "expect": ".jetpack-admin-shell-feature-off .jetpack-feature-off h1", "toContainText": "Social is off" }, { "expect": ".jetpack-admin-shell-feature-off .jetpack-feature-off__media img", "toBeVisible": true }, { "click": ".jetpack-admin-shell-feature-off form input[value^=\"Turn on\"]" }, { "expect": "#adminmenu a[href*=\"page=jetpack-social\"]", "toBeVisible": true }, { "expect": "#jetpack-social-dashboard-wp-admin-app", "toHaveCount": 1 }, { "expect": ".jetpack-feature-off", "toHaveCount": 0 }, { "expectNoConsoleErrors": true } ] }Not covered by the rehearsals: The admin shell card for a page that's already loaded. After a switch-off lands, My Jetpack removes the feature's sidebar item and nothing else links to the page, so the card can only be reached with Back/Forward, which a rehearsal can't use. To check it by hand:
wp jetpack module deactivate contact-form, which leaves the sidebar link in place, then click Forms. Or switch it off in Features and use the browser's Back button.