Skip to content

Jetpack AI: gate the AI Answers toggle on the Jetpack AI master switch (Search) - #50884

Draft
ariskataoka wants to merge 9 commits into
trunkfrom
add/search-ai-answers-master-gate
Draft

Jetpack AI: gate the AI Answers toggle on the Jetpack AI master switch (Search)#50884
ariskataoka wants to merge 9 commits into
trunkfrom
add/search-ai-answers-master-gate

Conversation

@ariskataoka

@ariskataoka ariskataoka commented Jul 29, 2026

Copy link
Copy Markdown
Member

Fixes #FORNO-427

Proposed changes

This PR gates the AI Answers toggle on the Jetpack AI master switch, behind the internal testing flag. Master off = toggle disabled in both UIs, endpoint rejects enabling, overlay and block render nothing — the saved choice persists for when the master returns.

Screenshots

Details
State
Baseline — master on, toggle usable
Master off (internal env) — toggle locked, saved choice still shown, notice explains why
Editor — AI Answer block shows the master-off notice (wins over the upgrade prompt)
Customberg — toggle disabled with matching help text
Same site, unproxied — the gate is inert on public requests: no lock, no notice

Related product discussion/links

  • FORNO-427

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

No.

Testing instructions

Needs a paid Jetpack Search plan and the Jetpack plugin.

  1. Enable Instant Search, then turn on Jetpack → Search → AI Answers (Preview) → Enable AI Answers.
  2. wp jetpack module deactivate ai, reload. The toggle is disabled but still checked, with "Jetpack AI is turned off for this site."; Personality and Save are disabled.
  3. POST jetpack/v4/search/settings {"ai_answers_enabled": true} → 400. POST /wp/v2/settings {"jetpack_search_ai_answers_enabled": true} → the option is stored (the choice persists, like the other AI feature options), but AI Answers stays off everywhere while the master is off.
  4. Search → Customize: the AI Answers toggle is disabled, with matching help text.
  5. wp jetpack module activate ai → enabled again, saved value restored.

@github-actions

github-actions Bot commented Jul 29, 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), and enable the add/search-ai-answers-master-gate branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack add/search-ai-answers-master-gate

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

@github-actions github-actions Bot added [Package] Search Contains core Search functionality for Jetpack and Search plugins [Status] In Progress [Tests] Includes Tests labels Jul 29, 2026
@github-actions

github-actions Bot commented Jul 29, 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: September 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 the [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. label Jul 29, 2026
@jp-launch-control

jp-launch-control Bot commented Jul 29, 2026

Copy link
Copy Markdown

Code Coverage Summary

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

File Coverage Δ% Δ Uncovered
projects/packages/search/src/dashboard/store/selectors/jetpack-settings.js 28/30 (93.33%) -6.67% 2 ❤️‍🩹
projects/packages/search/src/customberg/components/sidebar/sidebar-options.jsx 0/10 (0.00%) 0.00% 1 ❤️‍🩹
projects/packages/search/src/search-blocks/class-search-blocks.php 651/844 (77.13%) -0.09% 1 ❤️‍🩹
projects/packages/search/src/class-ai-answers.php 48/50 (96.00%) 0.65% 0 💚
projects/packages/search/src/class-helper.php 422/487 (86.65%) 0.03% 0 💚

Full summary · PHP report · JS report

@ariskataoka ariskataoka self-assigned this Jul 29, 2026
@ariskataoka
ariskataoka force-pushed the add/search-ai-answers-master-gate branch from 76e3373 to c7d7064 Compare July 30, 2026 03:54
@ariskataoka
ariskataoka marked this pull request as ready for review July 30, 2026 06:12
@ariskataoka ariskataoka changed the title Search: gate the AI Answers toggle on the Jetpack AI master switch Jetpack AI: gate the AI Answers toggle on the Jetpack AI master switch (Search) Jul 30, 2026
@ariskataoka
ariskataoka requested a review from Copilot July 30, 2026 06:23
@ariskataoka ariskataoka removed the [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. label Jul 30, 2026

Copilot AI 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.

Pull request overview

This PR ensures Jetpack Search’s AI Answers setting is correctly gated by the site-wide Jetpack AI master switch, preventing UI and API paths from enabling AI Answers when Jetpack AI is off while still preserving the user’s saved choice.

Changes:

  • Add a master-switch check (AI_Answers::is_master_enabled()) and apply it as a hard gate after filters when computing “enabled”.
  • Close write paths when the master is off (REST endpoint validation + sanitize_callback on the registered setting for /wp/v2/settings writes).
  • Update both dashboard and Customberg UIs to disable the toggle with explanatory copy while still showing the saved choice; expand test coverage accordingly.

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
projects/packages/search/tests/php/trait-toggles-ai-master.php Adds test helpers to simulate the presence and state of the Jetpack AI “master” module in package tests.
projects/packages/search/tests/php/Settings_Test.php Adds unit tests for the setting sanitize behavior under master-on/master-off scenarios.
projects/packages/search/tests/php/REST_Controller_Test.php Extends REST controller tests to cover master gating and new response fields (ai_master_enabled, ai_answers_saved).
projects/packages/search/tests/php/Initial_Javascript_State_Test.php Adds tests for reporting the master state in the initial JS payload.
projects/packages/search/tests/php/bootstrap.php Loads the new test trait in the package PHP test bootstrap.
projects/packages/search/tests/php/AI_Answers_Test.php Adds coverage for is_master_enabled(), saved vs effective enabled state, and the “cannot filter past master gate” behavior.
projects/packages/search/src/dashboard/store/selectors/jetpack-settings.js Adds selectors for ai_answers_saved and ai_master_enabled with backward-compatible defaults.
projects/packages/search/src/dashboard/hooks/use-search-settings.js Exposes the new selectors via the useSearchSettings() hook.
projects/packages/search/src/dashboard/components/test/ai-answers-tab.test.jsx Adds UI tests for disabled state, saved-choice display, and explanatory notice when master is off.
projects/packages/search/src/dashboard/components/ai-answers-tab/index.jsx Disables/annotates the toggle and keeps saved choice visible when the master is off; disables related controls.
projects/packages/search/src/customberg/components/sidebar/sidebar-options.jsx Disables the Customberg toggle and updates help text when the master is off using the initial state payload.
projects/packages/search/src/class-settings.php Adds optional sanitize_callback support and wires it for the AI Answers setting.
projects/packages/search/src/class-rest-controller.php Rejects enabling AI Answers via POST /jetpack/v4/search/settings when master is off; reports master + saved choice in get_settings().
projects/packages/search/src/class-helper.php Includes aiMasterEnabled in the initial JS state.
projects/packages/search/src/class-ai-answers.php Implements master-gate logic, saved-choice accessor, setting sanitizer, and applies the master gate after filters.
projects/packages/search/changelog/add-search-ai-answers-master-gate Adds a changelog entry for the gating change.

Comment thread projects/packages/search/changelog/add-search-ai-answers-master-gate Outdated
@ariskataoka
ariskataoka force-pushed the add/search-ai-answers-master-gate branch from c7d7064 to a74e29c Compare July 30, 2026 06:58
@ariskataoka
ariskataoka force-pushed the add/jetpack-ai-master-switch-module branch 2 times, most recently from 74ee3d3 to b982196 Compare August 6, 2026 07:23
@ariskataoka ariskataoka added this to the 16.2 milestone Aug 6, 2026
@ariskataoka
ariskataoka force-pushed the add/jetpack-ai-master-switch-module branch 4 times, most recently from a707b4b to 0fdf7d1 Compare August 7, 2026 12:21
Base automatically changed from add/jetpack-ai-master-switch-module to trunk August 9, 2026 23:58
@ariskataoka
ariskataoka marked this pull request as draft August 10, 2026 02:45
@ariskataoka
ariskataoka force-pushed the add/search-ai-answers-master-gate branch 3 times, most recently from 45d81f7 to d4b2f0e Compare August 12, 2026 14:18
@ariskataoka
ariskataoka force-pushed the add/search-ai-answers-master-gate branch from d4b2f0e to 9dcaefc Compare August 13, 2026 11:04
@ariskataoka
ariskataoka marked this pull request as ready for review August 13, 2026 12:49
@ariskataoka
ariskataoka marked this pull request as draft August 14, 2026 13:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants