[wp-trac] [WordPress Trac] #45107: Taxonomies should only be allowed to support one object type
WordPress Trac
noreply at wordpress.org
Wed Oct 17 16:48:28 UTC 2018
#45107: Taxonomies should only be allowed to support one object type
-------------------------+-------------------------------------------------
Reporter: desrosj | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Taxonomy | Version:
Severity: normal | Keywords: 2nd-opinion needs-patch needs-unit-
Focuses: | tests
-------------------------+-------------------------------------------------
Currently, taxonomies can be registered to any object type (posts,
comments, users, etc.). But core does not enforce a one to one limit for
object types to taxonomies, which can be problematic.
For example, if a taxonomy is registered to both users and posts, there
can be unintended consequences. Adding a term to a post with an ID of 3
would also cause a user with an ID of 3 to have that term. Removing that
term from the user would also affect the post. Unique IDs are only
enforced on a per object type basis, not accross all types.
The approach here would be to introduce a `_doing_it_wrong()` notice (and
possibly even return a `WP_Error`) when a taxonomy is registered to
multiple object types.
**Good:** `register_taxonomy( 'custom_tax_name', array( 'post', 'page',
'cpt' ) );`
**Bad:** `register_taxonomy( 'custom_tax_name', array( 'post', 'user' )
);`
== Why ==
Adding this to Core would open the door for the following potential
features:
- `WP_Tax_Query` support could be added to users (see #31383), comments,
etc.
- Built-in fields for taxonomy could be added to the REST API for users,
comments, etc.
- UIs could be added for users (also see #31383), comments, etc.
== Backward Compatibility ==
To continue supporting backward compatibility for sites that are
registering a taxonomy for multiple object types, `register_taxonomy()`
could continue working as is. The only change would be to return a
`WP_Error` and a `_doing_it_wrong()` notice.
In the future, `register_taxonomy()` could be changed to only register
objects with the same type as the first specified object type.
Example: `register_taxonomy( 'custom_tax_name', array( 'post', 'user',
'page' ) );` would only register the taxonomy for posts and pages (same
object type).
--
Ticket URL: <https://core.trac.wordpress.org/ticket/45107>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list