WordPress.org

Make WordPress Core


Ignore:
Timestamp:
08/26/2019 03:18:40 PM (8 weeks ago)
Author:
boonebgorges
Message:

Taxonomy: Fix unique-slug check for terms with parents.

wp_unique_term_slug() appends numeric suffixes when the requested slug is
already in use by a sibling term. Changes introduced in [32837] inadvertently
caused this suffixing to be skipped in cases where the requested slug is
suffixed with the parent slug, so that it became possible to have two terms
childslug-parentslug underneath to the same parentslug. We fix this
regression by ensuring that the numeric-suffix routine runs in all cases.

Props yashar_hv, saskak, dlh.
Fixes #46431.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/term/wpUniqueTermSlug.php

    r42343 r45893  
    128128        $this->assertEquals( 'bar-2', $actual );
    129129    }
     130
     131    /**
     132     * @ticket 46431
     133     */
     134    public function test_duplicate_parent_suffixed_slug_should_get_numeric_suffix() {
     135        $t1 = self::factory()->term->create(
     136            array(
     137                'taxonomy' => 'wptests_tax2',
     138                'name'     => 'Animal',
     139                'slug'     => 'animal',
     140            )
     141        );
     142
     143        $t2 = self::factory()->term->create(
     144            array(
     145                'taxonomy' => 'wptests_tax2',
     146                'name'     => 'Dog',
     147                'slug'     => 'dog',
     148            )
     149        );
     150
     151        $t3 = self::factory()->term->create(
     152            array(
     153                'taxonomy' => 'wptests_tax2',
     154                'name'     => 'Cat',
     155                'slug'     => 'dog-animal',
     156                'parent'   => $t1,
     157            )
     158        );
     159
     160        $t4 = self::factory()->term->create(
     161            array(
     162                'taxonomy' => 'wptests_tax2',
     163                'name'     => 'Giraffe',
     164                'slug'     => 'giraffe',
     165                'parent'   => $t1,
     166            )
     167        );
     168
     169        $term = get_term( $t4 );
     170
     171        $slug = wp_unique_term_slug( 'dog', $term );
     172
     173        $this->assertSame( 'dog-animal-2', $slug );
     174    }
    130175}
Note: See TracChangeset for help on using the changeset viewer.