Experiment: Add default term for taxonomies#78233
Conversation
| // true` would mark the form invalid whenever the toggle is off. | ||
| // Gate the requirement on the toggle via `custom` instead. | ||
| custom: ( item ) => { | ||
| if ( ! item.config.default_term_enabled ) { |
There was a problem hiding this comment.
This is tracked in the main issue under cross-cutting concerns
Fields with hidden through
isVisibleAPI that also have validation can make a DataForm invalid, even if we only want validation when the field is visible.
|
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. |
|
Size Change: -22 B (0%) Total Size: 7.96 MB 📦 View Changed
ℹ️ View Unchanged
|
Co-authored-by: Aki Hamano <54422211+t-hamano@users.noreply.github.com>
What?
Part of: #77600
Sort termsandSet a default term.term in this taxonomy automatically get the default, the same way "Uncategorized" works for categories.
Notes
WP core's
register_taxonomyresolves the default term by name only (term_exists()), and thedefault_term_{slug}option short-circuits after first creation. That has two user-visible consequences:doesn't find it under the new name, so WP inserts a new term and re-points the option. The old term stays in the
terms list. The field's help text reflects this: "Once saved, updating the name creates a new term — the previous
default term remains in the terms list."
edits to those args are silent no-ops. Rather than ship two fields that quietly do nothing on edit, the UI exposes the name only and points users to the terms list for slug/description edits.
Testing instructions
Posts), expandAdvancedcard and set a default term, enter a name (e.g. Featured), clickCreate.Auto-assign: create a new post and publish without touching the new taxonomy panel. Thedefault term should be checked in the taxonomy panel.
Disable: return to the taxonomy edit page, expand Advanced, toggle the default-term setting off, save. Createanother post and publish without touching the panel. No term should be checked.
Follow-ups
wp_user_taxonomyrecordleaves the
default_term_{slug}option and the auto-created default term behind. That's also why the new E2EafterEachcan't authoritatively clean up the term it creates — the current default term is protected from RESTdeletion (
rest_cannot_delete), and there's no REST endpoint to clear the option. A follow-up should cascade theseon
wp_user_taxonomy delete; the E2E cleanup can then be made strict (a TODO is in place).