Skip to content

[Blueprints] Flush rewrite rules after setting permalink structure - #3851

Merged
adamziel merged 1 commit into
trunkfrom
fix/set-site-options-flush-rewrite-rules
Jul 1, 2026
Merged

[Blueprints] Flush rewrite rules after setting permalink structure#3851
adamziel merged 1 commit into
trunkfrom
fix/set-site-options-flush-rewrite-rules

Conversation

@adamziel

@adamziel adamziel commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator

What it does

Flushes WordPress rewrite rules when the setSiteOptions Blueprint step changes permalink_structure.

{
  "step": "setSiteOptions",
  "options": {
    "permalink_structure": "/%postname%/"
  }
}

Before this change, the option was updated but rewrite_rules could remain missing or stale until WordPress regenerated them later. After this change, setSiteOptions calls flush_rewrite_rules(false) only when permalink_structure is present in the options payload.

Rationale

permalink_structure is 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

setSiteOptions now checks whether the submitted options include permalink_structure:

$flush_rewrite_rules = array_key_exists('permalink_structure', $site_options);

After updating all requested options, it calls:

flush_rewrite_rules(false);

The false argument avoids writing .htaccess; Playground only needs WordPress to regenerate the in-database rewrite rules.

Testing instructions

npm exec nx run playground-blueprints:test:vite -- --testFiles=packages/playground/blueprints/src/tests/steps/site-data.spec.ts
npm exec nx run playground-blueprints:typecheck
npm exec nx run playground-blueprints:lint
git diff --check

The new test deletes the rewrite_rules option, runs setSiteOptions with permalink_structure, and verifies that WordPress stores both the permalink structure and regenerated rewrite rules.

@adamziel
adamziel marked this pull request as ready for review July 1, 2026 10:44
@adamziel
adamziel requested review from a team, Copilot and mho22 July 1, 2026 10:44
@adamziel adamziel changed the title Flush rewrite rules after setting permalink structure Jul 1, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 setSiteOptions when permalink_structure is included in the submitted options.
  • Adds a test that deletes rewrite_rules, sets permalink_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.

Comment on lines +40 to +46
$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);
}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 0a65ff4: the permalink check now handles arrays with array_key_exists() and objects with property_exists() before the foreach/update loop.

Comment on lines +48 to +53
await php.run({
code: `<?php
require '/wordpress/wp-load.php';
delete_option('rewrite_rules');
`,
});

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 0a65ff4: the test now reads get_option("rewrite_rules") after delete_option() and asserts it is false before running setSiteOptions().

@adamziel
adamziel force-pushed the fix/set-site-options-flush-rewrite-rules branch from c9ca67f to 0a65ff4 Compare July 1, 2026 13:02
@adamziel
adamziel merged commit 435f81d into trunk Jul 1, 2026
100 of 103 checks passed
@adamziel
adamziel deleted the fix/set-site-options-flush-rewrite-rules branch July 1, 2026 13:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment