From dd11460efac22a9c9a75e1991ee61c887b3d0e78 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Wed, 16 Sep 2015 15:47:25 +0000 Subject: [PATCH] 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. Built from https://develop.svn.wordpress.org/trunk@34242 git-svn-id: http://core.svn.wordpress.org/trunk@34206 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/post-functions.php | 21 +++++++++++++++++++-- wp-includes/version.php | 2 +- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/wp-includes/post-functions.php b/wp-includes/post-functions.php index f82110417d..fe0d1cd8ce 100644 --- a/wp-includes/post-functions.php +++ b/wp-includes/post-functions.php @@ -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 ) { diff --git a/wp-includes/version.php b/wp-includes/version.php index 3bba55569e..384fc887c5 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.4-alpha-34241'; +$wp_version = '4.4-alpha-34242'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.