diff --git src/wp-includes/class-wp.php src/wp-includes/class-wp.php
index bba47ff..e6a1d1f 100644
|
|
class WP { |
303 | 303 | // Don't allow non-public taxonomies to be queried from the front-end. |
304 | 304 | if ( ! is_admin() ) { |
305 | 305 | foreach ( get_taxonomies( array( 'public' => false ), 'objects' ) as $taxonomy => $t ) { |
306 | | // Check first for taxonomy-specific query_var. |
307 | | if ( $t->query_var && isset( $this->query_vars[ $t->query_var ] ) ) { |
308 | | unset( $this->query_vars[ $t->query_var ] ); |
309 | | } |
310 | | |
311 | | // Next, check the 'taxonomy' query_var. |
| 306 | /* |
| 307 | * Disallow when set to the 'taxonomy' query var. |
| 308 | * Non-public taxonomies cannot register custom query vars. See register_taxonomy(). |
| 309 | */ |
312 | 310 | if ( isset( $this->query_vars['taxonomy'] ) && $taxonomy === $this->query_vars['taxonomy'] ) { |
313 | 311 | unset( $this->query_vars['taxonomy'], $this->query_vars['term'] ); |
314 | 312 | } |
diff --git tests/phpunit/includes/utils.php tests/phpunit/includes/utils.php
index 1b3686e..0a6dfc1 100644
|
|
function _cleanup_query_vars() { |
357 | 357 | unset( $GLOBALS[$v] ); |
358 | 358 | |
359 | 359 | foreach ( get_taxonomies( array() , 'objects' ) as $t ) { |
360 | | if ( ! empty( $t->query_var ) ) |
| 360 | if ( $t->public && ! empty( $t->query_var ) ) |
361 | 361 | $GLOBALS['wp']->add_query_var( $t->query_var ); |
362 | 362 | } |
363 | 363 | |
diff --git tests/phpunit/tests/taxonomy.php tests/phpunit/tests/taxonomy.php
index 5a6af2e..b78dfe6 100644
|
|
class Tests_Taxonomy extends WP_UnitTestCase { |
466 | 466 | /** |
467 | 467 | * @ticket 21949 |
468 | 468 | */ |
| 469 | public function test_it_should_be_possible_to_register_a_query_var_that_matches_the_name_of_a_nonpublic_taxonomy() { |
| 470 | global $wp; |
| 471 | |
| 472 | register_taxonomy( 'wptests_tax', 'post', array( |
| 473 | 'public' => false, |
| 474 | ) ); |
| 475 | $t = $this->factory->term->create_and_get( array( |
| 476 | 'taxonomy' => 'wptests_tax', |
| 477 | ) ); |
| 478 | |
| 479 | $p = $this->factory->post->create(); |
| 480 | wp_set_object_terms( $p, $t->slug, 'wptests_tax' ); |
| 481 | |
| 482 | add_filter( 'do_parse_request', array( $this, 'register_query_var' ) ); |
| 483 | $this->go_to( '/?wptests_tax=foo' ); |
| 484 | remove_filter( 'do_parse_request', array( $this, 'register_query_var' ) ); |
| 485 | |
| 486 | // Not a taxonomy... |
| 487 | $this->assertFalse( is_tax( 'wptests_tax' ) ); |
| 488 | |
| 489 | // ...but query var works. |
| 490 | $this->assertSame( 'foo', $wp->query_vars['wptests_tax'] ); |
| 491 | } |
| 492 | |
| 493 | public static function register_query_var( $r ) { |
| 494 | global $wp; |
| 495 | |
| 496 | $wp->add_query_var( 'wptests_tax' ); |
| 497 | |
| 498 | return $r; |
| 499 | } |
| 500 | |
| 501 | /** |
| 502 | * @ticket 21949 |
| 503 | */ |
469 | 504 | public function test_nonpublic_taxonomy_should_not_be_queryable_using_taxonomy_and_term_vars() { |
470 | 505 | register_taxonomy( 'wptests_tax', 'post', array( |
471 | 506 | 'public' => false, |