Guidelines: Drop default_term from wp_guideline_type taxonomy#77592
Guidelines: Drop default_term from wp_guideline_type taxonomy#77592
Conversation
Registering the taxonomy with default_term triggers cross-site clean_term_cache work, which caused major load on multisite installs with many sites even when no guidelines existed. Replace it with a save_post_wp_guideline callback that assigns the artifact fallback only when the post has no type term yet. The REST controller's singleton path already sets content explicitly via tax_input, so that flow is unaffected. Co-Authored-By: Claude Opus 4.7 (1M context) <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. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Covers: - Regression guard that the taxonomy is registered without default_term. - The save_post fallback assigns artifact only when the post has no type. - An explicit type passed via tax_input is preserved, not overwritten. - Updates to an existing post do not reset the term. - The hook is scoped to wp_guideline and leaves other post types alone. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Move the save_post_wp_guideline registration inside the register() method so it lives behind the same post_type_exists() guard as the CPT itself. If WordPress core ever ships the guidelines CPT and its own fallback hook, Gutenberg will skip both and avoid registering a duplicate callback. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
tyxla
left a comment
There was a problem hiding this comment.
This looks mostly good, but I have another potential concern about performance.
|
Flaky tests detected in de55e44. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/24876505973
|
wp_get_object_terms() queries the database directly on every call. get_the_terms() uses the object term cache populated by update_object_term_cache(), which keeps repeated reads cheap within the same request. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
tyxla
left a comment
There was a problem hiding this comment.
This is looking good and works well. 👍
I've added a few suggestions to address before landing it.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
I just cherry-picked this PR to the release/23.0 branch to get it included in the next release: 89ce73e |
* Guidelines: Drop default_term from wp_guideline_type registration Registering the taxonomy with default_term triggers cross-site clean_term_cache work, which caused major load on multisite installs with many sites even when no guidelines existed. Replace it with a save_post_wp_guideline callback that assigns the artifact fallback only when the post has no type term yet. The REST controller's singleton path already sets content explicitly via tax_input, so that flow is unaffected. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * Guidelines: Add unit tests for taxonomy default-term behavior Covers: - Regression guard that the taxonomy is registered without default_term. - The save_post fallback assigns artifact only when the post has no type. - An explicit type passed via tax_input is preserved, not overwritten. - Updates to an existing post do not reset the term. - The hook is scoped to wp_guideline and leaves other post types alone. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * Guidelines: Scope the save_post hook to Gutenberg's own registration Move the save_post_wp_guideline registration inside the register() method so it lives behind the same post_type_exists() guard as the CPT itself. If WordPress core ever ships the guidelines CPT and its own fallback hook, Gutenberg will skip both and avoid registering a duplicate callback. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * Guidelines: Use get_the_terms so the check hits the object term cache wp_get_object_terms() queries the database directly on every call. get_the_terms() uses the object term cache populated by update_object_term_cache(), which keeps repeated reads cheap within the same request. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * Guidelines: Drop redundant autosave check and cover revisions in tests Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com> Co-authored-by: gziolo <gziolo@git.wordpress.org> Co-authored-by: tyxla <tyxla@git.wordpress.org>
* Guidelines: Drop default_term from wp_guideline_type registration Registering the taxonomy with default_term triggers cross-site clean_term_cache work, which caused major load on multisite installs with many sites even when no guidelines existed. Replace it with a save_post_wp_guideline callback that assigns the artifact fallback only when the post has no type term yet. The REST controller's singleton path already sets content explicitly via tax_input, so that flow is unaffected. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * Guidelines: Add unit tests for taxonomy default-term behavior Covers: - Regression guard that the taxonomy is registered without default_term. - The save_post fallback assigns artifact only when the post has no type. - An explicit type passed via tax_input is preserved, not overwritten. - Updates to an existing post do not reset the term. - The hook is scoped to wp_guideline and leaves other post types alone. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * Guidelines: Scope the save_post hook to Gutenberg's own registration Move the save_post_wp_guideline registration inside the register() method so it lives behind the same post_type_exists() guard as the CPT itself. If WordPress core ever ships the guidelines CPT and its own fallback hook, Gutenberg will skip both and avoid registering a duplicate callback. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * Guidelines: Use get_the_terms so the check hits the object term cache wp_get_object_terms() queries the database directly on every call. get_the_terms() uses the object term cache populated by update_object_term_cache(), which keeps repeated reads cheap within the same request. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * Guidelines: Drop redundant autosave check and cover revisions in tests Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com> Co-authored-by: gziolo <gziolo@git.wordpress.org> Co-authored-by: tyxla <tyxla@git.wordpress.org> Co-authored-by: simison <87168+simison@users.noreply.github.com>
What
Stop passing
default_termwhen registering thewp_guideline_typetaxonomy. Assign theartifactfallback from asave_post_wp_guidelinehook instead, and only when the saved post has no type term yet.Why
Registering the taxonomy with
default_termroutes through core paths that trigger cross-siteclean_term_cachework. On multisite installations with a large number of sites (reported on WordPress.com after v23.0.0), this caused significant load even for sites with zero guidelines posts. Thedefault_termregistration argument also has limited precedent in core and is not well-tested under caching/invalidation scenarios.How
default_termargument fromregister_taxonomy().Gutenberg_Guidelines_Post_Type::ensure_default_type_term()that runs onsave_post_wp_guideline. Because that action fires afterwp_insert_post()processestax_input, any explicit term is already attached when the callback runs. The callback queries attached terms and only assignsartifactwhen none are present.contentviatax_input, so that path is a no-op for this new hook.Behavior
contentattached → hook is a no-op./wp-admincreate with a type chosen → user term attached → hook is a no-op.artifactassigned.Test plan
Gutenberg_Guidelines_REST_Controller_Testsuite passes (31 tests).init.wp_guidelinepost viawp-adminwithout picking a type → confirm it gets theartifactterm.wp_guidelinepost viawp-adminwith a type picked → confirm the picked term is preserved.contentterm is assigned.🤖 Generated with Claude Code