Make WordPress Core

Opened 9 months ago

Last modified 3 months ago

#53212 assigned enhancement

add post_type-specific version of the register_post_type_args filter

Reported by: pbiron Owned by: dlh
Milestone: 6.0 Priority: normal
Severity: normal Version:
Component: Posts, Post Types Keywords: needs-dev-note needs-unit-tests needs-patch
Focuses: Cc:


register_post_type_args can be used to filter the args used when registering a post type.

I suggest we add a post_type-specific version of this filter, i.e., register_post_type_{$post_type}_args, similar to many other "dynamic" filter names.

This would allow developers that only want to modify the args for 1 given post type to simplify their callback function by not needing to check the post type being registered before modifying the args.

That is, instead of writing:

add_filter( 'register_post_type_args', 'modify_args', 10, 2 );
function modify_args( $args, $post_type ) {
   if ( 'some_post_type' === $post_type ) {
      $args['supports'][] = 'page-attributes';

   return $args;

they could write the more straight forward:

add_filter( 'register_post_type_some_post_type_args', 'modify_args' );
function modify_args( $args, $post_type ) {
    $args['supports'][] = 'page-attributes';

   return $args;

Patch coming momentarily.

Attachments (1)

53212.diff (1.3 KB) - added by pbiron 9 months ago.

Download all attachments as: .zip

Change History (15)

9 months ago

#1 @pbiron
9 months ago

  • Keywords has-patch added

#2 @pbiron
9 months ago

Related: #50734

Maybe the DocBlock for the new filter in the patch should be amended to mention all the built-in post types, as described in the related ticket?

#3 @dlh
9 months ago

Having longed for a hook like this many times, I hope it won't blow the scope out of proportion to suggest that this effort might include a similar hook for after registration, and then equivalents of both hooks for taxonomies. So, object type-specific hooks for:

  • register_post_type_args
  • registered_post_type
  • register_taxonomy_args
  • registered_taxonomy

The use case in the description seems to me to apply to each of these hooks not-infrequently.

#4 @pbiron
9 months ago

I certainly have no objection :-) I opened the ticket just for register_post_type_args because that was my immediate need (for a plugin I'm writing at the moment).

Before refreshing the patch to include the other new hooks, I'll wait for others (e.g., a committer) to weigh in on the general idea. But doing it for the other hooks you suggest will be very straightforward and could be useful for me as well.

Last edited 9 months ago by pbiron (previous) (diff)

This ticket was mentioned in Slack in #core by pbiron. View the logs.

8 months ago

#6 @davidbaumwald
8 months ago

  • Keywords needs-dev-note added
  • Milestone changed from Awaiting Review to 5.8
  • Owner set to davidbaumwald
  • Status changed from new to accepted

Marking this for needs-dev-note for at least a small call-out on the Misc Dev Note.

#7 @pbiron
8 months ago

Thanx @davidbaumwald.

Just let me know if you want me to update the patch to include the additional filters mentioned by @dlh.

#8 @pbiron
8 months ago

@davidbaumwald what do you think? is this going to land today?

#9 @davidbaumwald
8 months ago

@pbiron I'm reviewing now. I think it's probably best to keep this ticket focused on the original scope, then open a follow-up ticket to add the other filters. I'm a little leery about adding too much at the Feature Freeze deadline without proper testing.

#10 @pbiron
8 months ago


I'm fine with keeping the focus as I originally stated it, as that solves my immediate need. And will be happy to open a follow up for the other filters.

If comment 2 needs to be addressed, I think that can be done after the feature freeze.

#11 @davidbaumwald
8 months ago

  • Milestone changed from 5.8 to 5.9

I'm moving this to 5.9 for more time to rollup the other filters and having some proper tests added for the new filters. Sorry for the false-start, @pbiron.

This ticket was mentioned in Slack in #core by hellofromtonya. View the logs.

3 months ago

#13 @hellofromTonya
3 months ago

  • Keywords needs-unit-tests added
  • Milestone changed from 5.9 to Future Release

Today is 5.9 feature freeze. With no activity in 6 months and work remaining to be done, punting this to 6.0, expect that milestone isn't available yet. Once it is, please feel free to move it into the milestone.

#14 @dlh
3 months ago

  • Keywords needs-patch added; has-patch removed
  • Milestone changed from Future Release to 6.0
  • Owner changed from davidbaumwald to dlh
  • Status changed from accepted to assigned

Per discussion in Slack, I'll work on an early patch that includes all of the proposed filters.

Note: See TracTickets for help on using tickets.