Skip to content

Admin shell: Offer to turn a switched-off feature back on when its page is opened - #55003

Merged
kraftbj merged 8 commits into
trunkfrom
add/admin-shell-feature-off-panel
Nov 18, 2026
Merged

kraftbj merged 8 commits into
trunkfrom
add/admin-shell-feature-off-panel

Conversation

@enejb

@enejb enejb commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

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-shell flag), 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)

  • The shell checks a gated page's feature every time it shows it: menu click, link, Back/Forward, returning to an already-loaded page, or the host's own load. It asks a new admin-ajax action, jetpack_admin_shell_feature. Each member's gate comes from the Admin_Menu item it already declares.
  • A page that hasn't loaded yet waits for the check; one that's already loaded shows at once and is swapped for the card. Most members drop out of the shell while their feature is off, so a missing member whose gate is off reads as "off" rather than as unknown.
  • The shell stands in only when the feature is off and the site says it can turn it on (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.
  • Each member's gate travels with a nonce created for that page and gate, and the feature endpoint answers only for that pair, so it can't be pointed at another module or product.
  • When the feature is off, the endpoint returns My Jetpack's card through the new jetpack_admin_shell_feature_off_card filter. The card's own script (progress, view tracking) is re-run after it's inserted, since innerHTML leaves scripts inert. Without a card, the shell shows a plain fallback panel.

My Jetpack (packages/my-jetpack)

  • Registers the activator and its offer check with admin-ui. The check (Menu_Visibility::offers()) adds one rule to My Jetpack: Offer to turn a switched-off feature back on when its page is opened #55037's can_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.
  • Hands the shell the card through the filter, with context: admin_shell for 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.
  • Maps Jetpack AI, Social and Search to their pages. They keep their pages while off, so this only matters in the shell.
  • Background: a wp-build dashboard copies its frame colour onto <body> as an inline style (@wordpress/boot's useSyncBodyBackground). 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)

  • Its sidebar item now declares 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

Forms opened, switched off, opened again, with no page load Jetpack AI, whose page stays while it's off
Admin shell showing the card in place of Forms Jetpack AI is off card in the admin shell
Social
Social is off

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 the jetpack-admin-shell flag set to on. The site had no standalone VideoPress plugin, and the duplicate production copy of Jetpack was deactivated.

  • In the shell: I opened My Jetpack, switched to VideoPress from the menu and back to My Jetpack, then switched VideoPress off through the Features tab's bulk endpoint and pressed Back. Everything stayed in the same document. The shell showed My Jetpack's "VideoPress is off" card in place of the page, with its heading focused.
  • Turn on: clicking Turn on VideoPress brought the VideoPress dashboard back with no card, and the module read as active.
  • Plugins: the plugin list was the same before and after (Akismet, Jetpack (dev) and Jetpack Beta active, Jetpack (production) inactive, and no 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 in wp_send_json_*(); the rehearsals below and the manual Back/Forward test exercise it, hence the Covered by non-unit tests label.

Related product discussion/links

  • Fast Jetpack Admin project.

Does this pull request change what data or activity we track or use?

No new events. #55037's jetpack_myjetpack_feature_off_view and jetpack_myjetpack_feature_off_turn_on_click gain context: admin_shell when the card shows in the shell.

Testing instructions

Turn on the jetpack-admin-shell flag (wp companion feature-flag enable jetpack-admin-shell on 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 · covers packages/my-jetpack, packages/forms, packages/admin-ui
Last 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 · covers packages/admin-ui, packages/my-jetpack, packages/publicize
Last 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:

  • With the shell flag on, open Jetpack › My Jetpack, click Forms in the sidebar, then click My Jetpack.
  • Switch Forms off with 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.
  • Expect the card without a page load. Turn on Forms reloads into Forms.

@enejb enejb self-assigned this Nov 16, 2026
@enejb enejb added the Enhancement Changes to an existing feature — removing, adding, or changing parts of it label Nov 16, 2026
@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

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:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Make sure to test your changes on all platforms that it applies to. You're responsible for the quality of the code you ship.
  3. You can use GitHub's Reviewers functionality to request a review.
  4. When it's reviewed and merged, you will be pinged in Slack to deploy the changes to WordPress.com simple once the build is done.

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:

  • WordPress.com Simple releases happen as soon as you deploy your changes after merging this PR (PCYsg-Jjm-p2).
  • WoA releases happen weekly.
  • Releases to self-hosted sites happen monthly:
    • Scheduled release: December 8, 2026
    • Code freeze: December 7, 2026

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.

@github-actions github-actions Bot added [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Package] Activity Log labels Nov 16, 2026
@enejb
enejb force-pushed the add/admin-shell-feature-off-panel branch from 3650a59 to f5032ed Compare November 16, 2026 22:41
@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WoA dev site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin (Jetpack or WordPress.com Site Helper), and enable the add/admin-shell-feature-off-panel branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack add/admin-shell-feature-off-panel
bin/jetpack-downloader test jetpack-mu-wpcom-plugin add/admin-shell-feature-off-panel

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

@jp-launch-control

jp-launch-control Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Code Coverage Summary

Coverage changed in 9 files. Only the first 5 are listed here.

File Coverage Δ% Δ Uncovered
projects/packages/admin-ui/src/class-admin-shell.php 294/337 (87.24%) -4.37% 20 💔
projects/packages/admin-ui/src/class-admin-menu.php 263/295 (89.15%) -2.93% 10 💔
projects/packages/admin-ui/src/admin-shell/chrome.js 26/39 (66.67%) -2.56% 1 ❤️‍🩹
projects/packages/activity-log/src/class-jetpack-activity-log.php 95/140 (67.86%) 0.47% 0 💚
projects/packages/my-jetpack/src/class-main-features.php 705/711 (99.16%) 0.00% 0 💚

1 file is newly checked for coverage.

File Coverage
projects/packages/admin-ui/src/admin-shell/feature.js 60/63 (95.24%) 💚

Full summary · PHP report · JS report

Coverage check overridden by Covered by non-unit tests Use to ignore the Code coverage requirement check when E2Es or other non-unit tests cover the code .

@enejb enejb added the Covered by non-unit tests Use to ignore the Code coverage requirement check when E2Es or other non-unit tests cover the code label Nov 16, 2026
@enejb
enejb force-pushed the add/admin-shell-feature-off-panel branch from 4556334 to a397457 Compare November 16, 2026 23:55
@enejb
enejb changed the base branch from trunk to add/turned-off-feature-page November 16, 2026 23:55
@github-actions github-actions Bot removed the [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ label Nov 16, 2026

@kraftbj kraftbj left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@enejb
enejb force-pushed the add/admin-shell-feature-off-panel branch from a397457 to 42aeb7b Compare November 17, 2026 18:41
@enejb
enejb force-pushed the add/admin-shell-feature-off-panel branch from 42aeb7b to b77cca7 Compare November 17, 2026 18:44
@enejb

enejb commented Nov 17, 2026

Copy link
Copy Markdown
Member Author

Thanks for the review. All four inline notes are addressed in 8d509a9; replies are on each thread. For the e2e request, specs/admin-shell/feature-off.test.ts adds two specs:

  • Back to a switched-off page: it opens Forms, switches back to My Jetpack, turns Forms off, then goes Back. The card must replace the page with its heading focused, outside any aria-hidden or inert subtree, the title must be announced politely, and no page-shown may fire for Forms.
  • Turn on from the card: the card's Turn on must bring Forms back.

Both pass in Chromium against the JN test site. The first one fails against the previous shell build, on the page-shown assertion.

@github-actions github-actions Bot added [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ E2E Tests labels Nov 17, 2026
@enejb
enejb force-pushed the add/admin-shell-feature-off-panel branch from 8d509a9 to 3b97d04 Compare November 17, 2026 19:30
kraftbj
kraftbj previously approved these changes Nov 17, 2026
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.
@kraftbj kraftbj added [Status] Ready to Merge Go ahead, you can push that green button! and removed [Status] In Progress labels Nov 18, 2026
@kraftbj
kraftbj added this pull request to stack #55156 November 18, 2026 13:50
Base automatically changed from add/turned-off-feature-page to trunk November 18, 2026 13:53
# 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
@kraftbj
kraftbj merged commit 6e94b70 into trunk Nov 18, 2026
134 checks passed
@kraftbj
kraftbj deleted the add/admin-shell-feature-off-panel branch November 18, 2026 15:57
@github-actions github-actions Bot added this to the jetpack/16.5 milestone Nov 18, 2026
@github-actions github-actions Bot added [Status] UI Changes Add this to PRs that change the UI so documentation can be updated. and removed [Status] Ready to Merge Go ahead, you can push that green button! labels Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Covered by non-unit tests Use to ignore the Code coverage requirement check when E2Es or other non-unit tests cover the code E2E Tests Enhancement Changes to an existing feature — removing, adding, or changing parts of it [Package] Activity Log [Package] Admin Ui [Package] My Jetpack [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Status] UI Changes Add this to PRs that change the UI so documentation can be updated. [Tests] Includes Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants