Repository navigation
fix: check theme directory writability before saving to prevent data loss - #914
Open
CookieDarb wants to merge 1 commit into
Open
CookieDarb wants to merge 1 commit into
CookieDarb wants to merge 1 commit into
Conversation
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.
What?
Prevents destructive data loss when attempting to save changes to an active theme whose directory lacks write permissions.
Closes #770
Why?
When saving theme changes in the Site Editor via Create Block Theme (
POST /create-block-theme/v1/save), the plugin writes the updated configuration to theme files (e.g.theme.json, templates, patterns) and then clears the corresponding user customizations from the database (e.g.clear_user_styles_customizations()clearingwp_global_styles).If the active theme directory is not writable (e.g., due to file ownership or permissions in containerized or shared hosting environments),
file_put_contents()triggers a PHP warning and fails silently. However, the endpoint still proceeded to wipe user customizations from the database and returned200 SUCCESS. The editor UI then displayed "Theme saved successfully" and reloaded the page, permanently destroying the user's unsaved changes without them ever being written to disk.How?
includes/class-create-block-theme-api.php:rest_save_theme()usingwp_is_writable( get_stylesheet_directory() ).403WP_Error(theme_not_writable). This ensures no database customizations are deleted, and triggers the existing frontend error notification snackbar in the Site Editor.tests/test-class-create-block-theme-api.php:test_save_endpoint_fails_when_theme_directory_not_writableto verify thatPOST /create-block-theme/v1/saverejects with HTTP403and codetheme_not_writablewhen the active theme directory is not writable, with fulltry ... finallycleanup.Testing Instructions
Use of AI Tools
AI assistance: Yes
Tool(s): Antigravity
Model(s): Gemini
Used for: Reviewing the existing implementation and suggesting the changes. Final decisions and edits were made by me.