Make WordPress Core

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

File register-post-type-args-filter.17447.v3.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..d44b059 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       
     1207        if ( empty( $args['_builtin'] ) ) {
     1208                $args = apply_filters( 'register_post_type_args', $args, $post_type );
     1209        }
     1210
    12041211        // Args prefixed with an underscore are reserved for internal use.
    12051212        $defaults = array(
    12061213                'labels'               => array(),
    function register_post_type( $post_type, $args = array() ) { 
    12301237                '_edit_link'           => 'post.php?post=%d',
    12311238        );
    12321239        $args = wp_parse_args( $args, $defaults );
    1233         $args = (object) $args;
    12341240
    1235         $post_type = sanitize_key( $post_type );
     1241        $args = (object) $args;
    12361242        $args->name = $post_type;
    12371243
    12381244        if ( strlen( $post_type ) > 20 )