WordPress.org

Make WordPress Core

Ticket #12729: 12729.3.diff

File 12729.3.diff, 1.6 KB (added by ryan, 18 months ago)

With unit tests that demonstrate the behavior change

  • tests/tests/term.php

     
    373373                $e = wp_insert_term( 'child-neighbor', $this->taxonomy, array( 'parent' => $c['term_id'] ) ); 
    374374                $this->assertEquals( 'child-neighbor-2', wp_unique_term_slug( 'child', $d_term ) ); 
    375375 
     376                $f = wp_insert_term( 'foo', $this->taxonomy ); 
     377                $this->assertInternalType( 'array', $f ); 
     378                $f_term = get_term( $f['term_id'], $this->taxonomy ); 
     379                $this->assertEquals( 'foo', $f_term->slug ); 
     380                $this->assertEquals( 'foo', wp_unique_term_slug(  'foo', $f_term ) ); 
     381 
     382                $g = wp_insert_term( 'foo',  $this->taxonomy ); 
     383                $this->assertInstanceOf( 'WP_Error', $g ); 
     384 
    376385                // clean up 
    377                 foreach ( array( $a, $b, $c, $d, $e ) as $t ) 
     386                foreach ( array( $a, $b, $c, $d, $e, $f ) as $t ) 
    378387                        $this->assertTrue( wp_delete_term( $t['term_id'], $this->taxonomy ) ); 
    379388        } 
    380389 
  • src/wp-includes/taxonomy.php

     
    23802380        } 
    23812381 
    23822382        // If we didn't get a unique slug, try appending a number to make it unique. 
    2383         if ( !empty($args['term_id']) ) 
    2384                 $query = $wpdb->prepare( "SELECT slug FROM $wpdb->terms WHERE slug = %s AND term_id != %d", $slug, $args['term_id'] ); 
     2383        if ( ! empty( $term->term_id ) ) 
     2384                $query = $wpdb->prepare( "SELECT slug FROM $wpdb->terms WHERE slug = %s AND term_id != %d", $slug, $term->term_id ); 
    23852385        else 
    23862386                $query = $wpdb->prepare( "SELECT slug FROM $wpdb->terms WHERE slug = %s", $slug ); 
    23872387