[wp-trac] [WordPress Trac] #53212: add post_type-specific version of the register_post_type_args filter

WordPress Trac noreply at wordpress.org
Fri May 14 22:21:02 UTC 2021


#53212: add post_type-specific version of the register_post_type_args filter
-------------------------------+-----------------------------
 Reporter:  pbiron             |      Owner:  (none)
     Type:  enhancement        |     Status:  new
 Priority:  normal             |  Milestone:  Awaiting Review
Component:  Posts, Post Types  |    Version:
 Severity:  normal             |   Keywords:
  Focuses:                     |
-------------------------------+-----------------------------
 [https://developer.wordpress.org/reference/hooks/register_post_type_args/
 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:

 {{{
 #!php

 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:

 {{{
 #!php

 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.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/53212>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list