Skip to content

Closes #1274: Add MCP option to Settings - #1349

Open
faisalahammad wants to merge 1 commit into
wp-media:developfrom
faisalahammad:enhancement/1274-mcp-settings-toggle
Open

faisalahammad wants to merge 1 commit into
wp-media:developfrom
faisalahammad:enhancement/1274-mcp-settings-toggle

Conversation

@faisalahammad

Copy link
Copy Markdown
Contributor

Description

Closes #1274

Adds an "MCP" toggle in Settings > Imagify, next to Imagify Analytics. Users can now turn off the Imagify MCP abilities without deactivating anything else. When MCP is off, the imagify/... abilities and category are not registered and the "install the MCP Adapter" notice is hidden. It is on by default, and existing sites stay on after the update, so current MCP users see no change.

Type of change

  • New feature (non-breaking change which adds functionality).
  • Bug fix (non-breaking change which fixes an issue).
  • Enhancement (non-breaking change which improves an existing functionality).
  • Breaking change (fix or feature that would cause existing functionality to not work as before).
  • Sub-task of #(issue number)
  • Chore
  • Release

Detailed scenario

What was tested

Manual (WP 6.9, valid API key):

  • The toggle shows next to Analytics with the text and the "Learn more about MCP" link (opens in a new tab). Both blocks stack on a narrow screen.
  • Turning it off and saving stores "mcp":0, the toggle stays off after reload, and no imagify/... ability is registered.
  • Turning it back on restores the abilities.
  • The adapter notice is hidden when MCP is off.

Automated:

  • composer test-unit: 607 tests OK.
  • Integration suite in wp-env: 251 tests OK, 37 skipped (multisite only). New tests cover the settings render, the adapter notice with MCP off, and the upgrade step.
  • composer phpcs on changed files and composer run-stan: clean.
  • New e2e test in Tests/e2e/specs/settings.spec.ts (needs IMAGIFY_TESTS_API_KEY).

How to test

  1. Use WordPress 6.9 or later with a valid Imagify API key.
  2. Open Settings > Imagify. Under General Settings, an "MCP" toggle is shown next to Imagify Analytics. It is ON.
  3. Turn it OFF and click "Save Changes". The toggle stays OFF and wp option get imagify_settings --format=json contains "mcp":0.
  4. Run wp eval 'print_r( array_keys( wp_get_abilities() ) );'. No imagify/... ability is listed.
  5. Turn it ON and save. The imagify/... abilities are back.
  6. On WordPress 6.8, the toggle is not shown and there is no PHP notice.
  7. Upgrade a site from 2.3.5: the toggle is ON after the first admin page load.

Affected Features & Quality Assurance Scope

  • Settings page, General Settings section (layout of the Analytics block changes to sit next to MCP).
  • MCP abilities registration (classes/MCP/AbilitiesSubscriber.php).
  • MCP Adapter admin notice (classes/MCP/AdapterNotice.php).
  • Plugin upgrade routine (inc/admin/upgrader.php).

Technical description

Documentation

  • New subscriber Imagify\MCP\SettingsSection renders views/part-settings-mcp.php on imagify_settings_after_lossless (priority 20, after Analytics). It returns early when wp_register_ability() does not exist.
  • New option mcp in Imagify_Options: default 0, reset value 1, sanitized as a boolean. This follows the same pattern as partner_links: a missing key reads as the default, so a default of 1 would make the box impossible to turn off.
  • The view adds a hidden mcp=0 input before the checkbox, because an unchecked box is not posted.
  • _imagify_new_upgrade() sets mcp to 1 for sites below 2.3.6, only when the key is not stored yet. On a network-activated install the options are shared, so this does not undo a choice made after another site upgraded.
  • AbilitiesSubscriber::register_categories() / register_abilities() and AdapterNotice::should_display() return early when mcp is off.
  • The mcp key is not added to the GetSettings / UpdateSettings abilities, so an MCP client cannot change it.

New dependencies

None.

Risks

  • The upgrade check uses 2.3.6 as the next version. If the release number is different, the string in inc/admin/upgrader.php must be updated.
  • The MCP block reuses the imagify-analytics-* toggle CSS classes so both look the same. The analytics JS binds by id, so it is not affected.

Mandatory Checklist

Code validation

  • I validated all the Acceptance Criteria. If possible, provide screenshots or videos.
  • I triggered all changed lines of code at least once without new errors/warnings/notices.
  • I implemented built-in tests to cover the new/changed code.

Code style

  • I wrote a self-explanatory code about what it does.
  • I protected entry points against unexpected inputs.
  • I did not introduce unnecessary complexity.
  • Output messages (errors, notices, logs) are explicit enough for users to understand the issue and are actionnable.

Unticked items justification

None.

Additional Checks

  • In the case of complex code, I wrote comments to explain it.
  • When possible, I prepared ways to observe the implemented system (logs, data, etc.)
  • I added error handling logic when using functions that could throw errors (HTTP/API request, filesystem, etc.)

- Add an MCP toggle next to Imagify Analytics in General Settings,
  shown only when the Abilities API is available (WP 6.9+)
- Skip ability and category registration when MCP is disabled
- Hide the MCP Adapter notice when MCP is disabled
- Default to on for new installs and keep it on for existing sites
  through the upgrade routine
- Add unit, integration and e2e tests

Closes wp-media#1274
@codacy-production

Copy link
Copy Markdown

Not up to standards ⛔

🔴 Issues 3 medium

Alerts:
⚠ 3 issues (≤ 1 issue of at least minor severity)

Results:
3 new issues

Category Results
UnusedCode 3 medium

View in Codacy

🟢 Metrics 0 complexity · 0 duplication

Metric Results
Complexity 0
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

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.

Add MCP option to Settings

1 participant