WordPress.org

Make WordPress Core

Changeset 36005


Ignore:
Timestamp:
12/18/2015 06:11:44 PM (4 years ago)
Author:
boonebgorges
Message:

Ensure that wp_list_categories() supports comma-separated lists for 'exclude' and 'exclude_tree'.

[34696] introduced a regression whereby comma-separated values for 'exclude'
and 'exclude_tree' would be handled improperly when merging the two parameters,
resulting in category IDs being incorrectly dropped from the combined array.

Props gblsm, hnle.
Fixes #35156.

Location:
trunk
Files:
2 edited

Legend:

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

    r35984 r36005  
    551551
    552552        if ( $r['exclude_tree'] ) {
    553             $exclude_tree = array_merge( $exclude_tree, (array) $r['exclude_tree'] );
     553            $exclude_tree = array_merge( $exclude_tree, wp_parse_id_list( $r['exclude_tree'] ) );
    554554        }
    555555
    556556        if ( $r['exclude'] ) {
    557             $exclude_tree = array_merge( $exclude_tree, (array) $r['exclude'] );
     557            $exclude_tree = array_merge( $exclude_tree, wp_parse_id_list( $r['exclude'] ) );
    558558        }
    559559
  • trunk/tests/phpunit/tests/category/wpListCategories.php

    r35242 r36005  
    308308        $this->assertNotContains( '<li class="cat-item cat-item-' . $child2 . '">', $actual );
    309309    }
     310
     311    /**
     312     * @ticket 35156
     313     */
     314    public function test_comma_separated_exclude_tree_should_be_merged_with_exclude() {
     315        $c = self::factory()->category->create();
     316        $parent = self::factory()->category->create( array( 'name' => 'Parent', 'slug' => 'parent' ) );
     317        $child = self::factory()->category->create( array( 'name' => 'Child', 'slug' => 'child', 'parent' => $parent ) );
     318        $parent2 = self::factory()->category->create( array( 'name' => 'Parent', 'slug' => 'parent2' ) );
     319        $child2 = self::factory()->category->create( array( 'name' => 'Child', 'slug' => 'child2', 'parent' => $parent2 ) );
     320        $parent3 = self::factory()->category->create( array( 'name' => 'Parent', 'slug' => 'parent3' ) );
     321        $child3 = self::factory()->category->create( array( 'name' => 'Child', 'slug' => 'child3', 'parent' => $parent3 ) );
     322        $parent4 = self::factory()->category->create( array( 'name' => 'Parent', 'slug' => 'parent4' ) );
     323        $child4 = self::factory()->category->create( array( 'name' => 'Child', 'slug' => 'child4', 'parent' => $parent4 ) );
     324
     325
     326        $args = array( 'echo' => 0, 'hide_empty' => 0, 'exclude_tree' => $parent );
     327
     328        $actual = wp_list_categories( array(
     329            'echo' => 0,
     330            'hide_empty' => 0,
     331            'exclude' => "$parent,$parent2",
     332            'exclude_tree' => "$parent3,$parent4",
     333        ) );
     334
     335        $this->assertContains( '<li class="cat-item cat-item-' . $c . '">', $actual );
     336
     337        $this->assertNotContains( '<li class="cat-item cat-item-' . $parent . '">', $actual );
     338        $this->assertNotContains( '<li class="cat-item cat-item-' . $parent2 . '">', $actual );
     339        $this->assertNotContains( '<li class="cat-item cat-item-' . $child . '">', $actual );
     340        $this->assertNotContains( '<li class="cat-item cat-item-' . $child2 . '">', $actual );
     341
     342        $this->assertNotContains( '<li class="cat-item cat-item-' . $parent3 . '">', $actual );
     343        $this->assertNotContains( '<li class="cat-item cat-item-' . $parent4 . '">', $actual );
     344        $this->assertNotContains( '<li class="cat-item cat-item-' . $child3 . '">', $actual );
     345        $this->assertNotContains( '<li class="cat-item cat-item-' . $child4 . '">', $actual );
     346    }
     347
     348    /**
     349     * @ticket 35156
     350     */
     351    public function test_array_exclude_tree_should_be_merged_with_exclude() {
     352        $c = self::factory()->category->create();
     353        $parent = self::factory()->category->create( array( 'name' => 'Parent', 'slug' => 'parent' ) );
     354        $child = self::factory()->category->create( array( 'name' => 'Child', 'slug' => 'child', 'parent' => $parent ) );
     355        $parent2 = self::factory()->category->create( array( 'name' => 'Parent', 'slug' => 'parent2' ) );
     356        $child2 = self::factory()->category->create( array( 'name' => 'Child', 'slug' => 'child2', 'parent' => $parent2 ) );
     357        $parent3 = self::factory()->category->create( array( 'name' => 'Parent', 'slug' => 'parent3' ) );
     358        $child3 = self::factory()->category->create( array( 'name' => 'Child', 'slug' => 'child3', 'parent' => $parent3 ) );
     359        $parent4 = self::factory()->category->create( array( 'name' => 'Parent', 'slug' => 'parent4' ) );
     360        $child4 = self::factory()->category->create( array( 'name' => 'Child', 'slug' => 'child4', 'parent' => $parent4 ) );
     361
     362
     363        $args = array( 'echo' => 0, 'hide_empty' => 0, 'exclude_tree' => $parent );
     364
     365        $actual = wp_list_categories( array(
     366            'echo' => 0,
     367            'hide_empty' => 0,
     368            'exclude' => array( $parent, $parent2 ),
     369            'exclude_tree' => array( $parent3, $parent4 ),
     370        ) );
     371
     372        $this->assertContains( '<li class="cat-item cat-item-' . $c . '">', $actual );
     373
     374        $this->assertNotContains( '<li class="cat-item cat-item-' . $parent . '">', $actual );
     375        $this->assertNotContains( '<li class="cat-item cat-item-' . $parent2 . '">', $actual );
     376        $this->assertNotContains( '<li class="cat-item cat-item-' . $child . '">', $actual );
     377        $this->assertNotContains( '<li class="cat-item cat-item-' . $child2 . '">', $actual );
     378
     379        $this->assertNotContains( '<li class="cat-item cat-item-' . $parent3 . '">', $actual );
     380        $this->assertNotContains( '<li class="cat-item cat-item-' . $parent4 . '">', $actual );
     381        $this->assertNotContains( '<li class="cat-item cat-item-' . $child3 . '">', $actual );
     382        $this->assertNotContains( '<li class="cat-item cat-item-' . $child4 . '">', $actual );
     383    }
    310384}
Note: See TracChangeset for help on using the changeset viewer.