Repository navigation
Rewrite Rules: Check the post type before reading the random base - #16066
mukeshpanchal27 wants to merge 2 commits into
Conversation
`wp_random_content_flush_rewrite_rules_for_post()` runs on every post insert and delete. It called `WP_Rewrite::get_random_base()` before checking the post type, so every revision, autosave, attachment and menu item read the random base. Reading the default base switches to the site locale and back, which is costly when the user locale differs from the site locale. This checks the post type and parent first, so only top-level pages and posts read the random base. Follow-up to [64402]. See #64498. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
wp_random_content_flush_rewrite_rules_for_post()is new in 7.2 and runs onwp_after_insert_postandafter_delete_post. Its first check was$wp_rewrite->get_random_base() === $page->post_name, and the post type check came second.The default random base is translatable. So
get_random_base()callsswitch_to_locale( get_locale() ), reads the string, and switches back. When the user locale differs from the site locale, each call fully switches the locale and back, which firesswitch_localeandrestore_previous_localeand resets text domains. This happened for every revision, autosave, attachment and menu item, although only top-level pages and posts can ever match.This PR checks the post type and parent first, so only top-level pages and posts read the random base. The behavior does not change: the same posts still flush the rewrite rules.
Tests
test_saving_posts_that_cannot_be_at_the_random_base_does_not_read_the_random_base(). It counts reads of the translatable random base while saving a child page, an attachment and a revision, all with the slugrandom.Tests_Query_RandomContentRedirectpass, including the existing flush tests.Trac ticket: https://core.trac.wordpress.org/ticket/64498
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Finding the issue while reviewing 7.2 changes, drafting the fix and test, and running the tests. I reviewed the final change.
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.
🤖 Generated with Claude Code