From 8573a86def7229bcf5c07d5375fd950f51ffb0d0 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Tue, 15 Sep 2015 18:54:30 +0000 Subject: [PATCH] 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 --- wp-includes/class-wp.php | 6 ++++-- wp-includes/post-functions.php | 7 +++++-- wp-includes/version.php | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/wp-includes/class-wp.php b/wp-includes/class-wp.php index 50d3638bdf..84111bca9f 100644 --- a/wp-includes/class-wp.php +++ b/wp-includes/class-wp.php @@ -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] ) ) diff --git a/wp-includes/post-functions.php b/wp-includes/post-functions.php index 6e1d0e3742..2d9f90960c 100644 --- a/wp-includes/post-functions.php +++ b/wp-includes/post-functions.php @@ -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' ) ) ) { diff --git a/wp-includes/version.php b/wp-includes/version.php index c84d761c17..e8919da8ca 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -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.