Repository navigation
Tag the new homepage, not the old one, when page_on_front changes - #817
Merged
Merged
Conversation
update_option_page_on_front gets the old value first, so the "homepage" page-type went to the previous homepage and was removed from the new one. Saving that previous page later made it the static homepage again (post_updated sets page_on_front for pages with that type). Register the hook with both arguments, tag the new value, and tag nothing when page_on_front is set to 0 (it tagged object 0 before). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
|
Test merged PR on Playground |
Contributor
✅ Code Coverage Report
🎉 Great job maintaining/improving code coverage! 📊 File-level Coverage Changes (1 files)📈 Coverage Improved
ℹ️ About this report
|
Contributor
🔍 WordPress Plugin Check Report
📊 Report
|
| 📍 Line | 🔖 Check | 💬 Message |
|---|---|---|
103 |
WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_post__not_in | Using exclusionary parameters, like post__not_in, in calls to get_posts() should be done with caution, see https://docs.wpvip.com/databases/optimize-queries/using-post__not_in/ for more information. |
📁 classes/suggested-tasks/providers/class-content-review.php (4 warnings)
| 📍 Line | 🔖 Check | 💬 Message |
|---|---|---|
232 |
WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_post__not_in | Using exclusionary parameters, like post__not_in, in calls to get_posts() should be done with caution, see https://docs.wpvip.com/databases/optimize-queries/using-post__not_in/ for more information. |
377 |
WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_post__not_in | Using exclusionary parameters, like post__not_in, in calls to get_posts() should be done with caution, see https://docs.wpvip.com/databases/optimize-queries/using-post__not_in/ for more information. |
381 |
WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_post__not_in | Using exclusionary parameters, like post__not_in, in calls to get_posts() should be done with caution, see https://docs.wpvip.com/databases/optimize-queries/using-post__not_in/ for more information. |
388 |
WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_post__not_in | Using exclusionary parameters, like post__not_in, in calls to get_posts() should be done with caution, see https://docs.wpvip.com/databases/optimize-queries/using-post__not_in/ for more information. |
📁 classes/activities/class-query.php (2 warnings)
| 📍 Line | 🔖 Check | 💬 Message |
|---|---|---|
71 |
PluginCheck.Security.DirectDB.UnescapedDBParameter | Unescaped parameter $table_name used in $wpdb->query()\n$table_name assigned unsafely at line 58. |
163 |
PluginCheck.Security.DirectDB.UnescapedDBParameter | Unescaped parameter $where_args used in $wpdb->get_results()\n$where_args assigned unsafely at line 153. |
📁 classes/suggested-tasks/data-collector/class-yoast-orphaned-content.php (1 warning)
| 📍 Line | 🔖 Check | 💬 Message |
|---|---|---|
111 |
PluginCheck.Security.DirectDB.UnescapedDBParameter | Unescaped parameter $query used in $wpdb->get_row()\n$query assigned unsafely at line 98. |
📁 classes/suggested-tasks/data-collector/class-terms-without-description.php (1 warning)
| 📍 Line | 🔖 Check | 💬 Message |
|---|---|---|
108 |
PluginCheck.Security.DirectDB.UnescapedDBParameter | Unescaped parameter $query used in $wpdb->get_results()\n$query assigned unsafely at line 106. |
📁 classes/suggested-tasks/data-collector/class-terms-without-posts.php (1 warning)
| 📍 Line | 🔖 Check | 💬 Message |
|---|---|---|
120 |
PluginCheck.Security.DirectDB.UnescapedDBParameter | Unescaped parameter $query used in $wpdb->get_results()\n$query assigned unsafely at line 118. |
🤖 Generated by WordPress Plugin Check Action • Learn more about Plugin Check
get_posts_by_type() caches its result for the request, so a second page_on_front change in the same request worked from a stale list and left the previous homepage tagged (the new test caught this). Use get_objects_in_term() instead: it is uncached and also finds drafts and leftover objects that the old hook tagged by mistake. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
WordPress keeps page_on_front when "Your latest posts" is chosen, so the former homepage kept the homepage page-type, and saving it later made post_updated() switch the site back to a static homepage. Untag on the switch away from a static homepage, and tag page_on_front again on the switch back. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The "homepage" page-type gets out of step with the actual homepage, and
post_updated()then switches the site's homepage on its own whenever a tagged page is saved:update_option_page_on_front()is hooked with one argument, and WordPress passes the old value first. Changing the homepage from page A to page B tagged A and untagged B; saving A later made A the static homepage again.page_on_front, so the hook doesn't run and the former homepage stays tagged. Saving it switched the site back to a static homepage.page_on_frontto 0 tagged object 0.Reproduced on a local site: switch the homepage from page 2 to page 12, then save page 2 without changing anything; the homepage goes back to page 2.
Fix
page_on_fronthook with both arguments and tag the new value; tag nothing for 0.get_objects_in_term()instead of the request-cachedget_posts_by_type(), so a second change in the same request isn't missed. This also clears drafts and leftover objects that the old hook tagged by mistake (on the next homepage change).update_option_show_on_fronthook: switching away from a static homepage removes the page-type; switching back tagspage_on_frontagain.Tests
test_update_option_page_on_front()(was an empty stub): new homepage tagged, previous untagged, saving the previous one keeps the homepage, a tagged draft is cleaned, 0 tags nothing.test_update_option_show_on_front(): switching to latest posts untags, saving the former homepage keeps latest posts, switching back re-tags.Checked locally on a real site with the fixed class: PHPCS, PHPStan, and all three scenarios above. PHPUnit runs in CI (no WP test library locally).
Generated with Claude Code