[wp-trac] [WordPress Trac] #38218: Introduce a WP_Post_Type_Labels class
WordPress Trac
noreply at wordpress.org
Thu Sep 13 07:01:33 UTC 2018
#38218: Introduce a WP_Post_Type_Labels class
------------------------------------------+-----------------------------
Reporter: swissspidy | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: Future Release
Component: Posts, Post Types | Version:
Severity: normal | Resolution:
Keywords: needs-patch needs-unit-tests | Focuses:
------------------------------------------+-----------------------------
Comment (by swissspidy):
Yeah so I added a PoC implementation two years ago for such a class:
https://core.trac.wordpress.org/attachment/ticket/26511/WP_Post_Type_Labels.diff
I imagined it to work like this:
1. Register a new post type A
2. Only define the `name` label and let `get_post_type_labels()` provide
the rest. (This is what many plugins do, in a nutshell)
3. `WP_Post_Type::$labels` is a magic method that returns an array
containing `name` plus any other labels provided on the fly by
`get_post_type_labels()`, either using a `WP_Post_Type_Label` class or
something else.
4. Register a new post type B
5. Pass a callback function to `labels` that returns an array with a
single key, `name`.
6. `WP_Post_Type::$labels` is a magic method that returns a merged array
of the callback's result + any missing labels from
`get_post_type_labels()`. Again, the specifics of that are TBD.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/38218#comment:7>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list