Skip to content

Closes #1322: Restore per-site MCP abilities on multisite, fix restore-media error and network admin notice - #1352

Open
remyperona wants to merge 7 commits into
developfrom
enhancement/1322-mcp-on-multisite-subsite
Open

remyperona wants to merge 7 commits into
developfrom
enhancement/1322-mcp-on-multisite-subsite

Conversation

@remyperona

@remyperona remyperona commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

🤖 AI-generated — created by an automated pipeline. Review before acting on this.

Closes #1322

Description

Restores the per-site MCP abilities for subsite admins on network-activated multisite (lost in #1302), fixes restore-media returning a permission error for unknown IDs, and shows the MCP migration notice in network admin. Network-wide abilities and custom-folders bulk optimization stay super-admin only.

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

QA passed all 6 acceptance criteria on a wp-env multisite, with Imagify both network-activated and activated per site. The QA report has the per-ability results and the two rows checked only by integration tests. Locally, the unit tests, the single-site and multisite integration tests, and the network-activated integration tests all pass, and CI is green.

How to test

On a multisite with Imagify network-activated, as an admin of one subsite only (not a super admin):

  1. bulk-optimize (wp) and generate-missing-nextgen are allowed. bulk-optimize (custom-folders), get-settings, update-settings, get-account, get-stats and get-nextgen-coverage are denied.
  2. restore-media with media_id 999999 returns Invalid media..
  3. As a super admin with mcp_refresh_jti_<user> meta and no MCP Adapter plugin, the migration notice shows on /wp-admin/network/ and links to the network plugin installer.
  4. Single-site and super-admin behaviour is unchanged.

Affected Features & Quality Assurance Scope

MCP abilities (classes/Abilities), capability contexts (classes/Context, NextGEN context), the MCP migration notice, the multisite CI jobs.

Technical description

Documentation

docs/api/mcp.md has the role table for each ability and explains the manage-site capability.

  • New manage-site capability in Context\WP. On network-activated installs it maps to manage_options, unless imagify_capacity customizes manage. In every other case it behaves exactly like manage.
  • AbstractContext::user_can() runs a second, deny-only filter pass for manage, so filters keyed on 'manage' still deny access and can never grant it. As a result, filters may run twice and must be idempotent.
  • The per-site abilities use the new AbstractAbility::has_site_manage_permission() check. Responses to a subsite admin leave out quota, reset date, upgrade link and custom-folder counts.
  • restore-media: an ID only counts as a custom-folder file if it exists in the custom-folders table.
  • AdapterNotice: also hooked to network_admin_notices.

New dependencies

None.

Risks

  • Subsite admins can spend the shared quota on their own site's media, but they cannot read the API key, settings or account details.
  • Capability filters may fire more than once per check (see above).
  • Unknown IDs now return Invalid media. to everyone. Admins with network access used to get This media is not optimized….

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

🤖 Generated with Claude Code

remyperona and others added 2 commits November 19, 2026 12:02
…activated multisite

Add a manage-site capacity describer so site admins keep the abilities that
act on their own site; network-wide abilities and custom folders stay
network-only. Fix restore-media treating any custom-folders ID as known,
trim account details for site-only callers, and show the MCP Adapter
migration notice in the network admin.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rk-activated legs

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@remyperona remyperona self-assigned this Nov 19, 2026
@codacy-production

codacy-production Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 1 medium

Results:
1 new issue

Category Results
UnusedCode 1 medium

View in Codacy

🟢 Metrics 17 complexity · 0 duplication

Metric Results
Complexity 17
Duplication 0

View in Codacy

🟢 Coverage 77.08% diff coverage

Metric Results
Coverage variation Report missing for 89848811
Diff coverage ✅ 77.08% diff coverage (50.00%)

View coverage diff in Codacy

Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (8984881) Report Missing Report Missing Report Missing
Head commit (d0cbfa1) 20635 2809 13.61%

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#1352) 48 37 77.08%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

1 Codacy didn't receive coverage data for the commit, or there was an error processing the received data. Check your integration for errors and validate that your coverage setup is correct.

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.

Comment thread docs/api/mcp.md Resolved
Comment thread classes/Abilities/RestoreMedia.php Resolved
@remyperona

remyperona commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor Author

Note

Generated by the AI delivery pipeline (lead-reviewer · Claude Opus 5.5).

Review: ✅ PASS

All three earlier blockers are resolved in d80823a, 86ad2d3 and fe27091: the next-gen impact count is now scoped to the run's contexts, the docs matrix is corrected, and the 'Invalid media.' behaviour is documented in the docs and readme.

@remyperona

remyperona commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor Author

Note

Generated by the AI delivery pipeline (qa-engineer · Claude Opus 5.5).

QA: ✅ PASS (re-QA at fe27091; first run was PARTIAL on a docs cell, now corrected)

Tested on a converted wp-env multisite (WP 6.9.6, subdirectory network, subsite /test1/, a user administering only /test1/), network-activated and per-site activated, at commit 87c04b4.

Acceptance Criterion Method Result Why it failed
1. Decision recorded (docs/api/mcp.md + readme.txt) Analysis ✅ —
2. docs/api/mcp.md states roles per ability, network-activated and per-site Analysis + WP-CLI ✅ (fixed in 86ad2d3) The imagify/bulk-optimize (custom-folders) row says a per-site-activation site admin is "allowed", but a site admin is denied there (manage_network_options on multisite, CustomFolders::get_capacity()). The page's own capability text says the same.
3. Subsite admin allowed on bulk-optimize (wp), generate-missing-nextgen, restore-media (real attachment); custom-folders bulk-optimize denied; network-wide abilities denied WP-CLI (check_permissions) ✅ —
4. restore-media 999999 returns Invalid media. for a subsite admin WP-CLI (execute) ✅ —
5. Migration notice on /wp-admin/network/, install link targets network installer Browser ✅ —
6. Super admin and single-site admin unchanged WP-CLI ✅ —

Network-activated, subsite admin on /test1/: allowed for bulk-optimize wp, generate-missing-nextgen, optimize-media, restore-media (attachment and 999999), get-media-status. Denied for bulk-optimize custom-folders, get-settings, update-settings, get-account, get-stats and get-nextgen-coverage. A user with no role on the subsite is denied everywhere. The super admin is allowed on everything.

Per-site activation: the subsite admin and the super admin are allowed on everything except that the site admin is denied custom-folders bulk-optimize.

Notice: the super admin, with mcp_refresh_jti_test meta, sees .imagify-mcp-adapter-notice on /wp-admin/network/. The link is /wp-admin/network/plugin-install.php?s=mcp-adapter&tab=search&type=term, and clicking it loads the network plugin installer. The notice is also present on /wp-admin/. Screenshot kept locally, not published: /private/tmp/claude-501/-Users-yui--claude-spares-spare-RWsM0d/fa31cf04-ff5f-4254-9053-c0b2c8caa48d/scratchpad/network-notice.png.

Blockers: none.

Re-QA at fe27091: every matrix row in docs/api/mcp.md was compared with observed WP-CLI results for a site admin of /test1/ and a super admin, network-activated and per-site; all match, including bulk-optimize custom-folders denied for the site admin in both modes and generate-missing-nextgen allowed in both. Criteria 3 and 4 are unchanged at HEAD (restore 999999 returns Invalid media.). Not verified: the custom-folder-file restore row (the custom-folders table is not provisioned in this env; covered by integration tests) and the generate-missing-nextgen confirmation impact estimate (CANNOT_VERIFY: the call stops at the invalid_api_key guard, and there is no .env.local to seed a key).

Environment notes (not PR defects):

  • vendor/wordpress/mcp-adapter is still present in the local vendor dir and autoloaded, so WP\MCP\Core\McpAdapter exists and hides the notice. I moved it aside temporarily to see the notice, then restored it.

remyperona and others added 4 commits November 19, 2026 12:11
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…a error

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…om folders

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…isite

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jeawhanlee

Copy link
Copy Markdown
Contributor

Note

Generated by the AI delivery pipeline (lead-reviewer · standalone).

Review: PASS

No blockers. Per-site abilities correctly use the new manage-site check; network-wide abilities (settings, account, stats, custom-folders) keep manage. Site-only callers get no quota, reset date or upgrade link. Dry run: nothing posted.

Inline findings (not posted):

  • classes/Context/WP.php:223 — [LOW] manage-site is derived by comparing the filtered manage capability to the string manage_network_options. A site that uses imagify_capacity to explicitly return manage_network_options (to force super-admin-only) is indistinguishable from the default, so subsite admins gain the per-site abilities. Consider deriving from the unfiltered default, or document this in docs/api/mcp.md.
  • classes/Abilities/AbstractAbility.php:62 — [LOW] The docblock says the imagify_capacity filter "can fire up to three times", while the PR description and AbstractContext say twice. Align the wording.
  • classes/Abilities/AbstractAbility.php:80 — [LOW] is_site_only_caller() re-runs two full capability checks, each with filter passes, every time a guard response is built. Cache the result per request, or compute manage once in has_site_manage_permission().

Nice-to-haves:

  • classes/Abilities/AbstractAbility.php — imagify_mcp_permission_denied still reports manage as required capability for per-site abilities that now accept manage-site. Telemetry will be slightly misleading.
  • readme.txt — changelog entry is under 2.3.6 while the plugin header is 2.3.5. Confirm the version bump is handled in the release PR.

Cross-file check: Context\CustomFolders, NGG and WP all handle manage-site. Any other ContextInterface implementation falls through to the default describer and denies safely. GenerateMissingNextgen::get_impact_estimate() no longer reveals network-wide custom-folder counts to site admins, because Bulk::get_contexts() only includes custom-folders in network admin.

Tests: PASS. Unit and integration tests cover the capability matrix, unknown-ID restore, the notice and the guard responses. CI now runs these in multisite and network-activated jobs.

suppressed: gh pr comment 1352 --body-file .TemporaryItems/Issues/imagify-plugin/review/1322.md

@jeawhanlee

jeawhanlee commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

@remyperona I think it's worth checking the inline-finding & Nice-to-haves

…and document the opt-out

The two deny-only passes for 'manage-site' each looked up the 'manage'
capacity, so imagify_capacity fired three times for 'manage' in one check.
It is now resolved once for both passes, and the docblocks state how often
each filter runs.

docs/api/mcp.md claimed a customized 'manage' could never be bypassed. A
filter that returns manage_network_options for 'manage' looks like the
default, so site admins still get the per-site abilities. The docs now say
so and show the supported opt-out: filter imagify_capacity for 'manage-site'.
Tests cover the opt-out, the documented limitation and the call count.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@remyperona

Copy link
Copy Markdown
Contributor Author

Note

Generated by the AI delivery pipeline (Claude Opus 5.5).

@jeawhanlee thanks for the review. Here's how each point was handled. The fixes are in d0cbfa1.

Inline findings

  1. WP.php:223, explicit manage_network_options counts as the default: fixed in the docs. docs/api/mcp.md said a customized manage could never be bypassed, which was wrong for this case. I kept the derivation from the filtered value. Deriving from the unfiltered default would make manage-site ignore every customization of manage, including stricter custom capabilities. Instead, the docs now explain the limitation and show the supported opt-out: filter imagify_capacity for 'manage-site'. That filter runs last, so its value is the one checked. New test rows cover the opt-out for site admins and super admins, and lock in the documented limitation.
  2. "Three times" vs "twice": fixed. Both counts were right, for different filters: imagify_capacity vs the two user-can filters. Still, the two deny passes each resolved the manage capacity. AbstractContext::user_can() now resolves it once for both passes, which brings imagify_capacity for manage down from 3 to 2 runs per manage-site check. The docblocks and docs now say which filter runs how often, and a new test counts the calls.
  3. Caching is_site_only_caller(): not changed. Only one guard response is built per call, so it runs once per call: two in-memory capability lookups. Caching would add per-request state that can go stale when the current user changes, for example with wp_set_current_user() in tests.

Nice-to-haves: kept as they are

  • imagify_mcp_permission_denied reporting manage: this is deliberate and documented in docs/api/mcp.md. Switching to manage-site would add a new value to the Mixpanel required_capability property, so it's a call for whoever reads those analytics.
  • readme.txt under 2.3.6: acceptance criterion 1 of MCP on multisite — subsite admin abilities, restore-media error and network admin notice #1322 asked for the decision to be recorded in readme.txt. The release PR bumps the header and Stable tag.

Tested in wp-env: the Context, Abilities and MCP integration groups on single site, multisite and network-activated, plus unit tests and PHPStan. All pass.

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.

MCP on multisite — subsite admin abilities, restore-media error and network admin notice

2 participants