Add `register_post_type_args` filter for changing `register_post_type()` arguments before further processing.

Does not apply to built-in post types.

Props MikeSchinkel, nickciske, engelen, swissspidy.
Fixes #17447.

git-svn-id: https://develop.svn.wordpress.org/trunk@34242 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov 2015-09-16 15:46:14 +00:00
parent d2bb55ee92
commit 10bc44d8fc
1 changed files with 19 additions and 2 deletions

View File

@ -984,8 +984,26 @@ function get_post_types( $args = array(), $output = 'names', $operator = 'and' )
function register_post_type( $post_type, $args = array() ) {
global $wp_post_types, $wp_rewrite, $wp;
if ( ! is_array( $wp_post_types ) )
if ( ! is_array( $wp_post_types ) ) {
$wp_post_types = array();
}
// Sanitize post type name
$post_type = sanitize_key( $post_type );
if ( empty( $args['_builtin'] ) ) {
/**
* Filter the arguments for registering a post type.
*
* Not available for built-in post types.
*
* @since 4.4.0
*
* @param array|string $args Array or string of arguments for registering a post type.
* @param string $post_type Post type key.
*/
$args = apply_filters( 'register_post_type_args', $args, $post_type );
}
// Args prefixed with an underscore are reserved for internal use.
$defaults = array(
@ -1018,7 +1036,6 @@ function register_post_type( $post_type, $args = array() ) {
$args = wp_parse_args( $args, $defaults );
$args = (object) $args;
$post_type = sanitize_key( $post_type );
$args->name = $post_type;
if ( empty( $post_type ) || strlen( $post_type ) > 20 ) {