WordPress.org

Make WordPress Core

Changeset 36108


Ignore:
Timestamp:
12/27/2015 04:40:13 PM (5 years ago)
Author:
boonebgorges
Message:

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.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/taxonomy.php

    r36080 r36108  
    391391            $args['query_var'] = sanitize_title_with_dashes( $args['query_var'] );
    392392        $wp->add_query_var( $args['query_var'] );
     393    } else {
     394        // Force query_var to false for non-public taxonomies.
     395        $args['query_var'] = false;
    393396    }
    394397
  • trunk/tests/phpunit/tests/taxonomy.php

    r35333 r36108  
    518518        $this->assertFalse( is_tax( 'wptests_tax' ) );
    519519    }
     520
     521    /**
     522     * @ticket 35089
     523     */
     524    public function test_query_var_should_be_forced_to_false_for_non_public_taxonomy() {
     525        register_taxonomy( 'wptests_tax', 'post', array(
     526            'public' => false,
     527            'query_var' => true,
     528        ) );
     529
     530        $tax = get_taxonomy( 'wptests_tax' );
     531        $this->assertFalse( $tax->query_var );
     532    }
    520533}
Note: See TracChangeset for help on using the changeset viewer.