Opened 7 years ago
Last modified 7 years ago
#41739 new enhancement
Support a "source" attribute in post types, taxonomies, and post statuses
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | 3.0 |
Component: | Posts, Post Types | Keywords: | |
Focuses: | Cc: |
Description
When registering custom post types, taxonomies, or post statuses, it would be nice to have a way to tell the system what plugin was responsible for those registrations.
Use Case:
In bbPress, there are 3 post types, 1 taxonomy, and 4 post statuses. There are several places where an "any bbPress post type" or "any bbPress post status" comparison is necessary, but it's somewhat annoying and repetitive to need to write:
array( bbp_get_forum_post_type(), bbp_get_topic_post_type(), bbp_get_reply_post_type() )
I'd prefer to write:
get_post_types( array( 'source' => 'bbpress' ) )
Tangentially, this could replace the otherwise vague internal
property, with:
'source' => 'wordpress'
I'm not confident that source
is the best descriptor, or if domain
or namespace
or something else might be more appropriate (without being too vague to be useful.)
Change History (2)
#2
in reply to:
↑ 1
@
7 years ago
Replying to SergeyBiryukov:
WP_Post_Type::set_props()
already sets any custom properties you pass toregister_post_type()
, so this appears to be possible without any special support from WordPress core.
Just tested by adding
'source' => 'bbpress'
to the post types inbbPress::register_post_types()
and checkingget_post_types( array( 'source' => 'bbpress' ) )
.
Yep! It will work, but... I think it's an idea worth officially endorsing and promoting as a best practice.
(I added it to bbPress as I was creating this ticket: https://bbpress.trac.wordpress.org/changeset/6672)
WP_Post_Type::set_props()
already sets any custom properties you pass toregister_post_type()
, so this appears to be possible without any special support from WordPress core.Just tested by adding
'source' => 'bbpress'
to the post types inbbPress::register_post_types()
and checkingget_post_types( array( 'source' => 'bbpress' ) )
.