wp_set_theme_file
Write a WordPress theme file with safety checks: dry-run preview, automatic revert on fatal errors, and read-back verification to prevent site downtime.
Instructions
Write one theme file. THIS EXECUTES CODE ON THE SITE - the highest-risk tool here.
A theme file is PHP. A syntax error does not break a layout, it takes the SITE down. Mitigations, in order:
the write goes through WordPress core's own theme editor, which makes a loopback request after writing and AUTOMATICALLY REVERTS the file if the site fatals;
the result carries
previous, the exact prior contents, so you can revert with a second call - KEEP IT;the write is verified by re-reading the file, and a mismatch is an error, never a success;
path traversal, absolute paths, and non-code extensions are refused, and a non-active theme needs allow_other_theme=true (editing a parent theme is how changes get lost on the next update - prefer the child theme). DEFAULTS TO dry_run=true, which writes nothing and returns the file's CURRENT contents next to what you propose. Read it and diff before setting dry_run=false. Prod writes require allow_prod=true. CREATING files is not supported - core's self-reverting editor only edits files the theme already has; add new files by deploy/SFTP first.
allow_createis accepted but cannot make creation work.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| file | Yes | ||
| theme | No | ||
| dry_run | No | ||
| install | Yes | ||
| contents | Yes | ||
| allow_prod | No | ||
| allow_create | No | ||
| allow_other_theme | No |