Skip to content

Fix #482: Use get_capacity() instead of current_user_can() in add_network_menus() - #1195

Open
Miraeld wants to merge 1 commit into
developfrom
fix/482-network-menu-capacity
Open

Fix #482: Use get_capacity() instead of current_user_can() in add_network_menus()#1195
Miraeld wants to merge 1 commit into
developfrom
fix/482-network-menu-capacity

Conversation

@Miraeld

@Miraeld Miraeld commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes #482

Imagify_Views->add_network_menus() passed a boolean (the return of ->current_user_can()) into the $capability argument of add_menu_page() / add_submenu_page(), which WordPress expects to be a capability string. This is the same class of bug fixed for the site menus in #441. The two custom-folder network menu entries now use ->get_capacity( 'bulk-optimize' ), consistent with the rest of the method (lines using get_capacity( 'manage' )) and with add_site_menus().

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/inspection — on a multisite network-activated install, confirmed the Imagify network-admin menu and its "Other Media" submenu register against the correct capability string (manage_network_options on multisite) rather than a coerced boolean. php -l passes.

How to test

  1. Network-activate Imagify on a multisite with custom-folders optimization available.
  2. In the Network Admin, confirm the Imagify → Bulk Optimization menu and Other Media submenu appear for a super admin and are correctly gated by capability (not shown to users lacking the capability).

Affected Features & Quality Assurance Scope

Network-admin menu registration only (multisite, network-activated). Single-site menus unaffected.

Technical description

Documentation

add_menu_page()/add_submenu_page() take a capability string in the 3rd/4th argument respectively. $context->current_user_can() returns a bool; $context->get_capacity( 'bulk-optimize' ) returns the proper capability string (manage_network_options on multisite). Two lines changed to use get_capacity(); the sibling manage lines in the same method already did this correctly.

New dependencies

None.

Risks

Minimal — aligns two lines with the established, already-used pattern in the same file. No behavior change for users who already had the capability; corrects the capability gate semantics.

Mandatory Checklist

Code validation

  • I validated all the Acceptance Criteria.
  • 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

Built-in tests: Imagify_Views has no existing unit coverage and this is a one-line-per-call string-vs-bool correction with an in-file precedent (add_site_menus()); adding a test harness for it would be disproportionate. Verified by inspection.

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

@codacy-production

codacy-production Bot commented Jul 22, 2026

Copy link
Copy Markdown

Not up to standards ⛔

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 duplication

Metric Results
Duplication 0

View in Codacy

🔴 Coverage 0.00% diff coverage

Metric Results
Coverage variation Report missing for 039662f1
Diff coverage 0.00% diff coverage (50.00%)

View coverage diff in Codacy

Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (039662f) Report Missing Report Missing Report Missing
Head commit (78ae3e1) 19952 917 4.60%

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 (#1195) 2 0 0.00%

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.

@Miraeld Miraeld self-assigned this Jul 22, 2026
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.

Network menu capacity issue

2 participants