Make WordPress Core


Ignore:
Timestamp:
10/21/2015 04:53:51 PM (11 years ago)
Author:
boonebgorges
Message:

Prevent non-public taxonomies from registering aquery var.

[34247] made the 'public' paramater of register_taxonomy() work by blocking
requests for non-public taxonomy archives during parse_request(). Blocking
taxonomy archive requests this late means that it's impossible to register an
independent query var that matches the slug of a non-public taxonomy. By
moving the block to register_taxonomy() - not allowing these taxonomies to
register their query vars in the first place - we free up the slug for other
use. In addition, we free up a bit of processing (no need to look for the query
var in parse_request() and better parallel the way non-public post types
work. See register_post_type().

Non-public taxonomy archives that are requested using ?taxonomy=tax_name are
still blocked during parse_request. It's only custom query vars -
?tax_name=term - that are affected by this change.

Props mboynes.
Fixes #21949.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/taxonomy.php

    r35242 r35333  
    467467         * @ticket 21949
    468468         */
     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         */
    469504        public function test_nonpublic_taxonomy_should_not_be_queryable_using_taxonomy_and_term_vars() {
    470505                register_taxonomy( 'wptests_tax', 'post', array(
Note: See TracChangeset for help on using the changeset viewer.