Skip to content

Tag the new homepage, not the old one, when page_on_front changes - #817

Merged
ilicfilip merged 3 commits into
developfrom
filip/homepage-type-new-value
Dec 4, 2026
Merged

ilicfilip merged 3 commits into
developfrom
filip/homepage-type-new-value

Conversation

@ilicfilip

@ilicfilip ilicfilip commented Dec 4, 2026 •

Copy link
Copy Markdown
Collaborator

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:

  1. 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.
  2. Switching Settings > Reading to "Your latest posts" keeps 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.
  3. Setting page_on_front to 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

  • Register the page_on_front hook with both arguments and tag the new value; tag nothing for 0.
  • Untag with get_objects_in_term() instead of the request-cached get_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).
  • New update_option_show_on_front hook: switching away from a static homepage removes the page-type; switching back tags page_on_front again.

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

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>
@github-actions

github-actions Bot commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Test merged PR on Playground
Test this pull request on the Playground
or download the zip

@github-actions

github-actions Bot commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

✅ Code Coverage Report

Metric Value
Total Coverage 37.46% 📉
Base Coverage 37.44%
Difference 📈 0.02%

⚠️ Coverage below recommended 40% threshold

🎉 Great job maintaining/improving code coverage!

📊 File-level Coverage Changes (1 files)

📈 Coverage Improved

Class Before After Change
Progress_Planner\Page_Types 53.68% 54.04% +0.36%
ℹ️ About this report
  • All tests run in a single job with Xdebug coverage
  • Security tests excluded from coverage to prevent output issues
  • Coverage calculated from line coverage percentages

@github-actions

github-actions Bot commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

🔍 WordPress Plugin Check Report

⚠️ Status: Passed with warnings

📊 Report

🎯 Total Issues ❌ Errors ⚠️ Warnings
10 0 10

⚠️ Warnings (10)

📁 classes/suggested-tasks/data-collector/class-unpublished-content.php (1 warning)
📍 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

ilicfilip and others added 2 commits December 4, 2026 11:16
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>
@ilicfilip
ilicfilip merged commit e5da73b into develop Dec 4, 2026
25 checks passed
@ilicfilip
ilicfilip deleted the filip/homepage-type-new-value branch December 4, 2026 10:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant