fix: widget CSS writability check fatals when WP_Filesystem() is unavailable - #2938
Open
lucadobrescu wants to merge 1 commit into
Open
fix: widget CSS writability check fatals when WP_Filesystem() is unavailable#2938lucadobrescu wants to merge 1 commit into
lucadobrescu wants to merge 1 commit into
Conversation
CSS_Handler::is_writable() called WP_Filesystem() before its function_exists() fallback, so a frontend request with an active sidebar and no generated widget stylesheet fataled with "Call to undefined function WP_Filesystem()" when the include did not expose the function. Run the guard first so the request degrades to the inline widget CSS fallback, and verify the initialized $wp_filesystem instance before reading its method. Adds an isolated-process PHPUnit regression test and a frontend e2e spec covering the blocked-filesystem fallback and the written-file path. Fixes #2937 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Contributor
Bundle Size Diff
|
Contributor
|
Plugin build for 5a47788 is ready 🛎️!
|
Contributor
There was a problem hiding this comment.
Pull request overview
Prevents frontend widget CSS generation from fatally calling an unavailable WordPress filesystem API.
Changes:
- Guards and validates filesystem initialization.
- Adds PHPUnit and E2E regression coverage.
- Extends E2E fixtures and classic-theme setup.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
inc/css/class-css-handler.php |
Safely checks filesystem availability. |
tests/test-css-handler.php |
Adds filesystem regression tests. |
tests/php/is-writable-sandbox.php |
Reproduces the missing-function condition. |
src/blocks/test/e2e/blocks/widgets-css-frontend.spec.js |
Tests inline fallback and file generation. |
src/blocks/test/e2e/fixtures.ts |
Adds widget/filesystem helpers. |
src/blocks/test/e2e/playwright.config.js |
Serializes the stateful E2E spec. |
packages/e2e-tests/mu-plugins/otter-e2e-bootstrap.php |
Adds E2E state-management endpoints. |
.wp-env.json |
Installs a classic theme with sidebars. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
E2E TestsPlaywright Test Status: See serial and parallel matrix jobs Performance ResultsserverResponse: {"q25":377.2,"q50":395.65,"q75":412.6,"cnt":10}, firstPaint: {"q25":1344.2,"q50":1445.35,"q75":1661.7,"cnt":10}, domContentLoaded: {"q25":3662.9,"q50":3709.25,"q75":3764.3,"cnt":10}, loaded: {"q25":3664.8,"q50":3711.2,"q75":3766.4,"cnt":10}, firstContentfulPaint: {"q25":4172.2,"q50":4198,"q75":4260.5,"cnt":10}, firstBlock: {"q25":14751.2,"q50":14919.9,"q75":15022.5,"cnt":10}, type: {"q25":30.15,"q50":31.11,"q75":31.77,"cnt":10}, typeWithoutInspector: {"q25":26.19,"q50":27.91,"q75":29.28,"cnt":10}, typeWithTopToolbar: {"q25":33.21,"q50":35.21,"q75":41.03,"cnt":10}, typeContainer: {"q25":16.56,"q50":18.57,"q75":19.92,"cnt":10}, focus: {"q25":138.43,"q50":147.76,"q75":151.71,"cnt":10}, inserterOpen: {"q25":46.76,"q50":47.85,"q75":49.41,"cnt":10}, inserterSearch: {"q25":17.32,"q50":19.34,"q75":20.65,"cnt":10}, inserterHover: {"q25":5.97,"q50":6.4,"q75":6.82,"cnt":20}, loadPatterns: {"q25":1831.26,"q50":1845.7,"q75":1895.2,"cnt":10}, listViewOpen: {"q25":236.75,"q50":246.18,"q75":262,"cnt":10} |
Contributor
Author
|
Copilot reviewed all 8 changed files and raised no comments, and every CI check is green — UnitTests, PHPStan, Phplint, JS Test, Performance, and both Playwright jobs (the new Verification recap:
No further changes needed from the review. 🤖 Generated with Claude Code |
Soare-Robert-Daniel
approved these changes
Jul 31, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A frontend request with an active sidebar and no generated widget stylesheet fataled with
Call to undefined function WP_Filesystem()duringwp_footer(production crash telemetry on Otter 3.2.0, issue #2937).CSS_Handler::is_writable()now checks that the function exists before it calls it, so the request degrades to the inline widget CSS fallback instead of dying.What changed
CSS_Handler::is_writable()— thefunction_exists( 'WP_Filesystem' )guard now runs before any call. Before → the guard sat after an unguardedWP_Filesystem()call atinc/css/class-css-handler.php:499and never protected anything. After → the method returnsfalseand the page renders with inline widget CSS. The return also verifies the initialized$wp_filesysteminstance before it reads->method.PHPUnit regression test —
tests/test-css-handler.phprunsis_writable()in a separate PHP process against a fakeABSPATHwhosewp-admin/includes/file.phpdefines nothing. On the old code the test fails with the exact production fatal; with the fix it asserts a cleanfalse.E2E spec —
src/blocks/test/e2e/blocks/widgets-css-frontend.spec.js(serial project) covers the crash path end to end: classic theme, Otter block in a sidebar, no generated stylesheet. With the filesystem blocked the page must finish rendering and serve the widget CSS inline; with the filesystem available a stylesheet file is written and enqueued on the next request.E2E infrastructure — the test mu-plugin gains
/otter-e2e/v1/filesystem(makeWP_Filesystem()fail to initialize),/otter-e2e/v1/widgets/seed, and/otter-e2e/v1/widgets/cleanup;.wp-env.jsoninstalls Twenty Twenty-One because block themes register no sidebars, so the widgets-CSS path is unreachable without a classic theme.Note
The exact production condition —
WP_Filesystem()still undefined after the include — cannot exist inside a loaded WordPress test site. The PHPUnit sandbox reproduces it in an isolated process; the e2e spec blocks the filesystem at theget_filesystem_method()level, which drives the sameis_writable() → falsebranch.Widgets CSS flow at
wp_footerflowchart LR A[wp_footer] --> B{Active<br/>sidebar?} B -- no --> Z[Done] B -- yes --> C{Generated CSS<br/>file exists?} C -- yes --> D[Enqueue stylesheet] C -- no --> E{Changed:<br/>filesystem usable?}:::changed E -- yes --> F[Write CSS file] --> G[Echo inline CSS] E -- no --> G classDef changed fill:#9a6700,color:#fff,stroke:#5c3d00,stroke-width:3px,stroke-dasharray:6 3Before this change, the "filesystem usable?" check itself fataled when
WP_Filesystem()was unavailable, so the request never reached either branch.QA
Activate a classic theme: go to
WP Admin → Appearance → Themesand activate Twenty Twenty-One.Go to
WP Admin → Appearance → Widgets. Add an Otter block (for example Progress Bar) to the Footer widget area and save.Simulate an unusable filesystem and clear the generated stylesheet:
Load any frontend page.
Expect: the page renders to the end, the widget is styled, and an inline
<style>with the block CSS sits in the footer. No fatal appears indebug.log.Remove
wp-content/mu-plugins/block-fs.phpand load a frontend page twice.Expect: the second load enqueues
link#otter-widgets-csspointing intouploads/themeisle-gutenberg/.Issue: #2937 (this PR targets
development, so GitHub does not auto-close on merge — link it via the Development sidebar).🤖 Generated with Claude Code