Make WordPress Core

Ticket #17447: register-post-type-args-filter.17447.v2.diff

File register-post-type-args-filter.17447.v2.diff, 967 bytes (added by engelen, 11 years ago)

Coarse-grained approach to filtering the arguments to register_post_type, which the filter applied before parsing with default arguments

  • src/wp-includes/post.php

    diff --git src/wp-includes/post.php src/wp-includes/post.php
    index 85d0d16..19acb7d 100644
    function register_post_type( $post_type, $args = array() ) { 
    12011201        if ( ! is_array( $wp_post_types ) )
    12021202                $wp_post_types = array();
    12031203
     1204        // Sanitize post type name
     1205        $post_type = sanitize_key( $post_type );
     1206       
    12041207        // Args prefixed with an underscore are reserved for internal use.
    12051208        $defaults = array(
    12061209                'labels'               => array(),
    function register_post_type( $post_type, $args = array() ) { 
    12301233                '_edit_link'           => 'post.php?post=%d',
    12311234        );
    12321235        $args = wp_parse_args( $args, $defaults );
    1233         $args = (object) $args;
    12341236
    1235         $post_type = sanitize_key( $post_type );
     1237        if ( false == $args['_builtin'] ) {
     1238                $args = apply_filters( 'register_post_type_args', $args, $post_type );
     1239        }
     1240
     1241        $args = (object) $args;
    12361242        $args->name = $post_type;
    12371243
    12381244        if ( strlen( $post_type ) > 20 )