Force non-public taxonomies to have a query_var of `false`.

[35333] implemented `public=false` for taxonomies. The implementation prevented
non-public taxonomies from having their archives accessed via query_var during
a normal request. But it didn't prevent non-public taxonomies from registering
their query vars in the `$wp_taxonomies` global. The latter implementation
details causes problems specifically when a taxonomy is registered with
`query_var=true`; for public taxonomies, `register_taxonomy()` translates this
into a query_var equivalent to the taxonomy name, but in the case of non-public
taxonomies, the query_var was set to the boolean itself. The boolean then
causes problems when using non-strict comparison to filter taxonomy objects by
query_var, as when using `get_taxonomies()`.

This changeset addresses the issue by forcing the query_var property of
non-public taxonomies to `false`.

Fixes #35089.

git-svn-id: https://develop.svn.wordpress.org/trunk@36108 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Boone Gorges 2015-12-27 16:40:13 +00:00
parent 7e3d2c3e4c
commit ba1f056a26
2 changed files with 16 additions and 0 deletions

View File

@ -390,6 +390,9 @@ function register_taxonomy( $taxonomy, $object_type, $args = array() ) {
else
$args['query_var'] = sanitize_title_with_dashes( $args['query_var'] );
$wp->add_query_var( $args['query_var'] );
} else {
// Force query_var to false for non-public taxonomies.
$args['query_var'] = false;
}
if ( false !== $args['rewrite'] && ( is_admin() || '' != get_option( 'permalink_structure' ) ) ) {

View File

@ -517,4 +517,17 @@ class Tests_Taxonomy extends WP_UnitTestCase {
$this->assertFalse( is_tax( 'wptests_tax' ) );
}
/**
* @ticket 35089
*/
public function test_query_var_should_be_forced_to_false_for_non_public_taxonomy() {
register_taxonomy( 'wptests_tax', 'post', array(
'public' => false,
'query_var' => true,
) );
$tax = get_taxonomy( 'wptests_tax' );
$this->assertFalse( $tax->query_var );
}
}