Repository navigation
Explain the hidden Publishing section on the settings screen - #46
Conversation
A user who can open Settings -> Terraviz (manage_options) but lacks the plugin's manage_terraviz capability saw the service-token fields simply missing, which reads as a missing feature rather than a permission. Render the Publishing section header for them with a notice that names the capability and how to get it: ask an administrator to enter the token or grant the capability (with a role-editor plugin, or a WP-CLI command pre-filled with the user's id). An administrator missing the capability -- usually because the plugin was enabled without its activation hook -- is told to deactivate and reactivate the plugin instead. The credential fields and their save path stay gated on manage_terraviz exactly as before. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MKEqjkVyUQiZZL7QTk9m64 Signed-off-by: Claude <noreply@anthropic.com>
🖼️ Visual report12 shot(s) · 2 viewport(s) (desktop, mobile) · 3 with changes Regression: 3 shot(s) changed, 0 new (no baseline), threshold 0.001.
All 12 shot(s)
Full gallery (actuals + Advisory — the Screenshots workflow is kept out of the core CI gate, so this never blocks a merge. Visual review only. |
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MKEqjkVyUQiZZL7QTk9m64 Signed-off-by: Claude <noreply@anthropic.com>
There was a problem hiding this comment.
🟡 Changes recommended
The administrator recovery advice does not resolve explicit per-user capability denials.
1 open finding
What changed in this PR
Explains why Publishing settings are hidden from users without manage_terraviz, while preserving existing credential authorization.
Changes:
- Adds a locked Publishing notice with role-specific recovery guidance.
- Tests notices and credential visibility for three permission states.
- Documents the change in the changelog.
| File | Description |
|---|---|
| tests/unit/SettingsPublishingSectionTest.php | Tests permission-dependent notices and fields. |
| src/Settings.php | Adds the locked Publishing section and guidance. |
| CHANGELOG.md | Records the new settings notice. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
The locked Publishing notice told any administrator without the capability to deactivate and reactivate the plugin. That only re-grants it to the administrator role, so it cannot help when the capability is explicitly denied on the user (caps[manage_terraviz] = false), which outranks any role grant. Detect that case first and say so, with the `wp user remove-cap` command that lifts the denial; reactivation advice stays for an administrator whose role simply lacks the grant. The administrator test had simulated the missing grant with exactly such a per-user denial, so it asserted the wrong advice. It now removes the cap from the administrator role (and restores it), and a new test covers the per-user denial. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MKEqjkVyUQiZZL7QTk9m64 Signed-off-by: Claude <noreply@anthropic.com>

Summary
A user who can open Settings → Terraviz (
manage_options) but lacks the plugin'smanage_terravizcapability saw the Publishing section — the Cloudflare Access service-token Client ID / Client Secret fields — silently missing. That reads as a missing feature rather than a permission, and is what a user with a custom "Developer" role ran into while setting up a test site.This PR renders the Publishing section header for such users with a notice in place of the fields:
manage_terravizand to ask a site administrator to either enter the token themselves or grant the capability — with a role-editor plugin, or a WP-CLI command pre-filled with the viewer's user id (wp user add-cap <id> manage_terraviz).manage_terraviz => false, which outranks any role grant, so reactivation can't lift it) are told so, with the command that removes the denial (wp user remove-cap <id> manage_terraviz).The credential fields, their
sanitize_credentialsave path, and the "Verify credential" action remain gated onmanage_terravizexactly as before — this only changes what a user without the capability sees.Changes
src/Settings.php—register_publishing()registers the section with a newrender_publishing_locked()callback when the current user lacksmanage_terraviz.tests/unit/SettingsPublishingSectionTest.php— renders the settings sections for four cases (manage_optionswithout the capability; administrator whose role lacks it; per-user denial; capability holder) and asserts the right notice / fields appear. The role case removes and restores the administrator role's grant; the others grant or deny per user.CHANGELOG.md—[Unreleased]→ Added entry.mainto pick up the wp-env 11.17 Screenshots fix (Move wp-env to 11.17 so the Screenshots workflow can start WordPress #47).Testing
phpunit --testsuite unitagainst the WP test suite (latest WordPress, PHP 8.3): 223 tests, 749 assertions, all passing (also in reverse order). The per-user-denial test fails against the earlier version of the notice.phpcs: 0 errors (the one warning is pre-existing, intests/unit/CryptoTest.php).semgrep scan --config p/php --config p/security-audit --config p/secrets: 0 findings.maincaptured all 12 shots; Settings screen and Publisher dashboard unchanged. Its admin login holdsmanage_terraviz, so the notice never renders there.🤖 Generated with Claude Code
https://claude.ai/code/session_01MKEqjkVyUQiZZL7QTk9m64