In WP::parse_request(), don't add query vars of non-viewable post types to WP::public_query_vars. In register_post_type(), don't add query vars of non-viewable post types to WP::public_query_vars.

In `_unregister_post_type()` (unit tests), don't add query vars of non-viewable post types to `WP::public_query_vars`.

Adds unit test.

Fixes #30018.

Built from https://develop.svn.wordpress.org/trunk@34215


git-svn-id: http://core.svn.wordpress.org/trunk@34179 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Scott Taylor 2015-09-15 18:54:30 +00:00
parent d5e02c6129
commit 8573a86def
3 changed files with 10 additions and 5 deletions

View File

@ -261,9 +261,11 @@ class WP {
*/
$this->public_query_vars = apply_filters( 'query_vars', $this->public_query_vars );
foreach ( get_post_types( array(), 'objects' ) as $post_type => $t )
if ( $t->query_var )
foreach ( get_post_types( array(), 'objects' ) as $post_type => $t ) {
if ( is_post_type_viewable( $t ) && $t->query_var ) {
$post_type_query_vars[$t->query_var] = $post_type;
}
}
foreach ( $this->public_query_vars as $wpvar ) {
if ( isset( $this->extra_query_vars[$wpvar] ) )

View File

@ -1072,12 +1072,15 @@ function register_post_type( $post_type, $args = array() ) {
add_post_type_support( $post_type, array( 'title', 'editor' ) );
}
if ( false !== $args->query_var && ! empty( $wp ) ) {
if ( false !== $args->query_var ) {
if ( true === $args->query_var )
$args->query_var = $post_type;
else
$args->query_var = sanitize_title_with_dashes( $args->query_var );
$wp->add_query_var( $args->query_var );
if ( $wp && is_post_type_viewable( $args ) ) {
$wp->add_query_var( $args->query_var );
}
}
if ( false !== $args->rewrite && ( is_admin() || '' != get_option( 'permalink_structure' ) ) ) {

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.4-alpha-34214';
$wp_version = '4.4-alpha-34215';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.