Skip to content

Docs: Example for blueprint step writeFile flushes permalink rewrites rules on every page load #2195

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
eliot-akira opened this issue Apr 21, 2025 · 0 comments

Comments

@eliot-akira
Copy link
Collaborator

Making a note of something I noticed in the documentation.

The example for the blueprint step writeFile shows how to create a mu-plugin that enables pretty permalinks.

{
  "step": "writeFile",
  "path": "/wordpress/wp-content/mu-plugins/rewrite.php",
  "data": "<?php /* Use pretty permalinks */ add_action( 'after_setup_theme', function() { global $wp_rewrite; $wp_rewrite->set_permalink_structure('/%postname%/'); $wp_rewrite->flush_rules(); } );"
}

Expanding the code:

<?php
/* Use pretty permalinks */
add_action( 'after_setup_theme', function() {
  global $wp_rewrite;
  $wp_rewrite->set_permalink_structure('/%postname%/');
  $wp_rewrite->flush_rules();
} );

The after_setup_theme action is called on every page load, so it's not the best way to enable pretty permalinks and flush rewrite rules (which is considered an "expensive" operation).

A better way is to do it once using the runPHP step.

{
  "step": "runPHP",
  "code": "<?php include '/var/www/html/wp-load.php'; global $wp_rewrite; $wp_rewrite->set_permalink_structure('/%postname%/'); $wp_rewrite->flush_rules();"
},

There might be a simpler way to achieve it. This PR seems to have made pretty permalinks the default.

update_option('permalink_structure', '/%year%/%monthnum%/%day%/%postname%/');

This method does not flush rewrite rules. Maybe it's not needed because it's always run on a freshly created site.

Anyway, if the default is to use pretty permalinks, then the above mentioned example in the docs is unnecessary and could be removed altogether.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Inbox
Development

No branches or pull requests

1 participant