Skip to content

fix: preserve experiment settings when ai is globally disabled#353

Open
turtlepod wants to merge 1 commit intoWordPress:developfrom
turtlepod:fix/ai-settings-hidden-fields-on-disable
Open

fix: preserve experiment settings when ai is globally disabled#353
turtlepod wants to merge 1 commit intoWordPress:developfrom
turtlepod:fix/ai-settings-hidden-fields-on-disable

Conversation

@turtlepod
Copy link
Copy Markdown

@turtlepod turtlepod commented Mar 30, 2026

What?

Closes #352
Ensures per-experiment enable/disable settings are not cleared when the site admin uses Disable AI and saves, so Enable AI restores the same feature toggles as before.

Why?

With AI globally off, experiment checkboxes are disabled. Disabled fields are not submitted with the form. options.php still updates every option registered for the settings page; when a key is missing from POST, the saved value becomes empty/null, which wiped each wpai_feature_{id}_enabled option. After re-enabling AI, every experiment appeared off until configured again.

How?

  • When AI is on: keep the usual pattern of a hidden 0 plus the checkbox (1) so unchecked experiments still save as off.
  • When AI is off: output a hidden input per experiment carrying the current stored value, and render the visible checkbox without a name (still disabled, same id for the label) so only the hidden value is submitted and options stay intact.
    Adds an e2e test: enable Title Generation, toggle global AI off then on, assert the Title Generation checkbox remains checked.

Use of AI Tools

  • Tooling: [e.g. Cursor / Copilot / ChatGPT — fill in what you used]
  • Extent: [e.g. implementation suggested for the hidden-field approach and e2e scenario; human reviewed, tested, and adjusted as needed]

Testing Instructions

  1. Go to Settings → AI (with valid connectors so the page loads as usual).
  2. Turn AI on. Enable several experiments (e.g. Title Generation, Alt Text), click Save Changes, confirm success.
  3. Click Disable AI (form auto-submits). Confirm AI is off and experiment checkboxes are disabled.
  4. Click Enable AI again.
  5. Confirm the same experiments are still checked as in step 2 (no need to re-check each one).
  6. Optional: uncheck one experiment, save, disable/enable AI again, confirm only your intentional change persists.

Testing Instructions for Keyboard

  1. Tab to Disable AI / Enable AI and activate with Enter or Space; confirm the form submits and focus returns to a sensible place after reload.
  2. With AI enabled, tab to experiment checkboxes, toggle with Space, save with Submit / Save Changes; confirm behavior matches before (no regression).
  3. With AI disabled, tab past experiment rows; confirm disabled controls are still in tab order (or skipped per browser) as before—no new traps or focus loops.

Screenshots or screencast

n/a

Open WordPress Playground Preview

Copilot AI review requested due to automatic review settings March 30, 2026 02:15
@github-actions
Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: turtlepod <turtlepod@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes a settings persistence bug where per-experiment enable/disable options were being reset when “AI is globally disabled” and the settings form was submitted, ensuring that re-enabling AI restores the prior experiment toggle state.

Changes:

  • Update settings page rendering to always submit per-experiment values even when AI is globally disabled (via hidden inputs).
  • Add an e2e regression test covering disable → enable roundtrip while preserving a specific experiment toggle.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
includes/Settings/Settings_Page.php Preserves per-experiment option values by submitting hidden fields when global AI is disabled and omitting the checkbox name to prevent overwrites.
tests/e2e/specs/admin/settings.spec.js Adds an e2e test asserting an experiment remains enabled after toggling global AI off and back on.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 30, 2026

Codecov Report

❌ Patch coverage is 0% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 57.66%. Comparing base (32c5e2d) to head (4df6db9).

Files with missing lines Patch % Lines
includes/Settings/Settings_Page.php 0.00% 9 Missing ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##             develop     #353      +/-   ##
=============================================
- Coverage      57.85%   57.66%   -0.19%     
- Complexity       615      618       +3     
=============================================
  Files             46       46              
  Lines           3165     3175      +10     
=============================================
  Hits            1831     1831              
- Misses          1334     1344      +10     
Flag Coverage Δ
unit 57.66% <0.00%> (-0.19%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Collaborator

@dkotter dkotter left a comment

Choose a reason for hiding this comment

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

Overall this looks good to me though noting this entire settings page will likely change in the next release coming out of #340. I think worth holding this PR until that is merged and then likely will need changes here to still support this (or the issue may go away once that PR is merged)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Experiment toggles are cleared after “Disable AI” is saved

3 participants