fix(rucss): show admin notice when Used-CSS subfolder has no write permissions#8323
fix(rucss): show admin notice when Used-CSS subfolder has no write permissions#8323Miraeld wants to merge 2 commits into
Conversation
Adds full .aiassistant/ setup with issue workflow, QA engineer agent, knowledge graph builder (880 PHP/JS nodes indexed), architecture and compliance skills, and PHPCS specs. Adapted for wp-rocket: single edition, WP_Rocket\ namespace, Subscriber/ServiceProvider/Container patterns, wpm_apply_filters_typed enforcement, fix/enhancement/test branch prefixes, and TDD testing guide.
…rmissions When a Used-CSS subfolder is created but has incorrect write permissions, write_used_css() now detects the permission failure, stores the subfolder path in a transient, and notice_write_permissions() surfaces it as an admin notice — consistent with how the base-folder write-permission notice already works. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Duplication | 0 |
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.
QA Report — PR #8323 / Issue #8268Validation StrategyCode-analysis QA (no live browser testing required — this is a background job + admin notice flow). Reviewed all five changed/added files, then ran the new unit tests in isolation and the full RUCSS unit suite, and ran PHPCS on the two changed source files. Test ResultsNew tests only (9 tests): Full RUCSS unit suite (64 tests): The single "risky" test is a pre-existing issue in PHPCS on changed source files: Code Review Findings
Minor observation (non-blocking): Acceptance Criteria Validation
VerdictPASS ✅ The implementation is correct, complete, and consistent with existing RUCSS patterns. All 9 new tests pass, the full RUCSS suite (64 tests) is green, and PHPCS is clean. The acceptance criteria from issue #8268 are fully satisfied. Notes
QA performed by GitHub Copilot CLI — code analysis only. |
|
In this one I don't think the solution, while it works, is the best one. It should modify the That way the check is done earlier than when running RUCSS jobs, and it doesn't need to use a transient (which can expire) to show the issue. |
Description
Fixes #8268
When the Used-CSS feature creates a per-URL subfolder (e.g.
wp-content/cache/used-css/example.com/path/) but that subfolder has incorrect write permissions, WP Rocket was silently failing — the CSS was not saved and no feedback was given to the admin. This PR detects that silent failure and surfaces it as an admin notice pointing the admin to the specific subfolder, consistent with the existing notice already shown when the base Used-CSS folder is not writable.Type of change
Detailed scenario
What was tested
Automated (unit tests — 9 new tests, all passing):
getNotWritableSubfolder— when no transient is set → returns empty string; when transient is set → returns path and deletes the transient.writeUsedCssSubfolderPermission— whenwrite_file()fails and subfolder is not writable → transient is set; whenwrite_file()fails but subfolder is writable → no transient set.noticeWritePermissions— covers all 5 branches: insufficient capability, RUCSS disabled, base folder not writable (existing notice), subfolder transient empty (no notice), subfolder transient set (new notice).Full RUCSS unit suite: 64/64 pass — no regressions.
PHPCS: exit 0 on all changed files.
How to test
Prerequisites:
Steps to reproduce the bug (before this fix) / validate the fix:
wp-content/cache/used-css/<host>/wp-content/cache/used-css/example.com/some-path/chmod 555 wp-content/cache/used-css/example.com/some-path/wp action-scheduler run)Expected result (with this fix): An admin notice is displayed identifying the non-writable subfolder and asking the admin to fix the permissions.
Expected result (without this fix / regression check): No notice is shown — silent failure.
Verify base-folder notice still works:
chmod 555 wp-content/cache/used-css/Affected Features & Quality Assurance Scope
Technical description
Documentation
Root cause:
Filesystem::write_used_css()creates a per-URL subfolder viamkdir, then writes the gzipped CSS viaWP_Filesystem::write_file(). Ifwrite_file()returnsfalse(which happens when the subfolder is not writable), the method returnedfalsesilently. The existingnotice_write_permissions()only checked the base folder (/used-css/), so the subfolder failure was invisible.Solution — transient bridge:
The write failure occurs inside an Action Scheduler background job. The admin notice fires on
admin_noticesduring a regular page load. A WordPress transient bridges these two async contexts (consistent withrocket_saas_processingused elsewhere in RUCSS).Filesystem::write_used_css()(changed):Filesystem::get_not_writable_subfolder()(new):UsedCSS::notice_write_permissions()(changed):The notice message mirrors the existing base-folder notice, replacing the folder path with the specific subfolder path.
New dependencies
None.
Risks
is_writable()will returntrueand no transient is set — the failure remains silent for those edge cases, which is the same behavior as before this fix.get_transientis a single option read, called only onadmin_notices(admin page loads only).Mandatory Checklist
Code validation
Code style
Unticked items justification
N/A — all mandatory items are ticked.
Additional Checks