Make WordPress Core


Ignore:
Timestamp:
02/13/2016 03:50:37 AM (11 years ago)
Author:
boonebgorges
Message:

Introduce publicly_queryable taxonomy argument.

Taxonomies registered as publicly_queryable can be queried as taxonomy
archives.

If not provided explicitly, the value of publicly_queryable is inherited
from public.

Props Chouby.
Fixes #34491.

File:
1 edited

Legend:

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

    r36247 r36525  
    447447         * @ticket 21949
    448448         */
    449         public function test_nonpublic_taxonomy_should_not_be_queryable_using_taxname_query_var() {
     449        public function test_nonpublicly_queryable_taxonomy_should_not_be_queryable_using_taxname_query_var() {
    450450                register_taxonomy( 'wptests_tax', 'post', array(
    451                         'public' => false,
     451                        'publicly_queryable' => false,
    452452                ) );
    453453
    … …  
    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() {
     469        public function test_it_should_be_possible_to_register_a_query_var_that_matches_the_name_of_a_nonpublicly_queryable_taxonomy() {
    470470                global $wp;
    471471
    472472                register_taxonomy( 'wptests_tax', 'post', array(
    473                         'public' => false,
     473                        'publicly_queryable' => false,
    474474                ) );
    475475                $t = $this->factory->term->create_and_get( array(
    … …  
    502502         * @ticket 21949
    503503         */
    504         public function test_nonpublic_taxonomy_should_not_be_queryable_using_taxonomy_and_term_vars() {
     504        public function test_nonpublicly_queryable_taxonomy_should_not_be_queryable_using_taxonomy_and_term_vars() {
     505                register_taxonomy( 'wptests_tax', 'post', array(
     506                        'publicly_queryable' => false,
     507                ) );
     508
     509                $t = self::factory()->term->create_and_get( array(
     510                        'taxonomy' => 'wptests_tax',
     511                ) );
     512
     513                $p = self::factory()->post->create();
     514                wp_set_object_terms( $p, $t->slug, 'wptests_tax' );
     515
     516                $this->go_to( '/?taxonomy=wptests_tax&term=' . $t->slug );
     517
     518                $this->assertFalse( is_tax( 'wptests_tax' ) );
     519        }
     520
     521        /**
     522         * @ticket 34491
     523         */
     524        public function test_public_taxonomy_should_be_publicly_queryable() {
     525                register_taxonomy( 'wptests_tax', 'post', array(
     526                        'public' => true,
     527                ) );
     528
     529                $this->assertContains( 'wptests_tax', get_taxonomies( array( 'publicly_queryable' => true ) ) );
     530
     531                $t = self::factory()->term->create_and_get( array(
     532                        'taxonomy' => 'wptests_tax',
     533                ) );
     534
     535                $p = self::factory()->post->create();
     536                wp_set_object_terms( $p, $t->slug, 'wptests_tax' );
     537
     538                $this->go_to( '/?wptests_tax=' . $t->slug );
     539
     540                $this->assertTrue( is_tax( 'wptests_tax' ) );
     541        }
     542
     543        /**
     544         * @ticket 34491
     545         */
     546        public function test_private_taxonomy_should_not_be_publicly_queryable() {
    505547                register_taxonomy( 'wptests_tax', 'post', array(
    506548                        'public' => false,
    507549                ) );
    508550
     551                $this->assertContains( 'wptests_tax', get_taxonomies( array( 'publicly_queryable' => false ) ) );
     552
    509553                $t = self::factory()->term->create_and_get( array(
    510554                        'taxonomy' => 'wptests_tax',
    … …  
    514558                wp_set_object_terms( $p, $t->slug, 'wptests_tax' );
    515559
    516                 $this->go_to( '/?taxonomy=wptests_tax&term=' . $t->slug );
     560                $this->go_to( '/?wptests_tax=' . $t->slug );
    517561
    518562                $this->assertFalse( is_tax( 'wptests_tax' ) );
     563        }
     564
     565        /**
     566         * @ticket 34491
     567         */
     568        public function test_private_taxonomy_should_be_overridden_by_publicly_queryable() {
     569                register_taxonomy( 'wptests_tax', 'post', array(
     570                        'public' => false,
     571                        'publicly_queryable' => true,
     572                ) );
     573
     574                $this->assertContains( 'wptests_tax', get_taxonomies( array( 'publicly_queryable' => true ) ) );
     575
     576                $t = self::factory()->term->create_and_get( array(
     577                        'taxonomy' => 'wptests_tax',
     578                ) );
     579
     580                $p = self::factory()->post->create();
     581                wp_set_object_terms( $p, $t->slug, 'wptests_tax' );
     582
     583                $this->go_to( '/?wptests_tax=' . $t->slug );
     584
     585                $this->assertTrue( is_tax( 'wptests_tax' ) );
    519586        }
    520587
Note: See TracChangeset for help on using the changeset viewer.