[Blueprints] Flush rewrite rules after setting permalink structure - #3851
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR ensures WordPress rewrite rules are regenerated immediately when the Blueprint setSiteOptions step updates permalink_structure, preventing stale or missing rewrite_rules during the same boot.
Changes:
- Conditionally flushes rewrite rules from
setSiteOptionswhenpermalink_structureis included in the submitted options. - Adds a test that deletes
rewrite_rules, setspermalink_structure, and asserts rewrite rules are regenerated.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| packages/playground/blueprints/src/lib/steps/site-data.ts | Adds conditional flush_rewrite_rules(false) when permalink_structure is present. |
| packages/playground/blueprints/src/tests/steps/site-data.spec.ts | Adds regression test validating rewrite rules are regenerated after setting permalinks. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| $flush_rewrite_rules = array_key_exists('permalink_structure', $site_options); | ||
| foreach($site_options as $name => $value) { | ||
| update_option($name, $value); | ||
| } | ||
| if ($flush_rewrite_rules) { | ||
| flush_rewrite_rules(false); | ||
| } |
There was a problem hiding this comment.
Addressed in 0a65ff4: the permalink check now handles arrays with array_key_exists() and objects with property_exists() before the foreach/update loop.
| await php.run({ | ||
| code: `<?php | ||
| require '/wordpress/wp-load.php'; | ||
| delete_option('rewrite_rules'); | ||
| `, | ||
| }); |
There was a problem hiding this comment.
Addressed in 0a65ff4: the test now reads get_option("rewrite_rules") after delete_option() and asserts it is false before running setSiteOptions().
c9ca67f to
0a65ff4
Compare
What it does
Flushes WordPress rewrite rules when the
setSiteOptionsBlueprint step changespermalink_structure.{ "step": "setSiteOptions", "options": { "permalink_structure": "/%postname%/" } }Before this change, the option was updated but
rewrite_rulescould remain missing or stale until WordPress regenerated them later. After this change,setSiteOptionscallsflush_rewrite_rules(false)only whenpermalink_structureis present in the options payload.Rationale
permalink_structureis not just display metadata. It changes how WordPress maps pretty URLs to posts, pages, feeds, embeds, and other routes.Updating the option without flushing rewrite rules can leave a Playground in a split state:
get_option('permalink_structure')reports the new structure, but requests still rely on old or missing rewrite rules. That matters for Blueprints that set permalink structure and then immediately import content, run checks, or expect pretty URLs to resolve in the same boot.This PR extracts one v1 step behavior from #3725 so it can be reviewed on its own.
Implementation
setSiteOptionsnow checks whether the submitted options includepermalink_structure:After updating all requested options, it calls:
The
falseargument avoids writing.htaccess; Playground only needs WordPress to regenerate the in-database rewrite rules.Testing instructions
The new test deletes the
rewrite_rulesoption, runssetSiteOptionswithpermalink_structure, and verifies that WordPress stores both the permalink structure and regenerated rewrite rules.