From 39171d75272015fb797c0ab8100b6ad9dc5bc023 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Fri, 23 Aug 2013 21:04:22 +0000 Subject: [PATCH] Check `term_id` against the `$term` object, not the non-existent var `$args`. Props rboren. Fixes #12729. git-svn-id: https://develop.svn.wordpress.org/trunk@25106 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/taxonomy.php | 4 ++-- tests/tests/term.php | 11 ++++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/wp-includes/taxonomy.php b/src/wp-includes/taxonomy.php index 955369e228..aa7798d7e5 100644 --- a/src/wp-includes/taxonomy.php +++ b/src/wp-includes/taxonomy.php @@ -2380,8 +2380,8 @@ function wp_unique_term_slug($slug, $term) { } // If we didn't get a unique slug, try appending a number to make it unique. - if ( !empty($args['term_id']) ) - $query = $wpdb->prepare( "SELECT slug FROM $wpdb->terms WHERE slug = %s AND term_id != %d", $slug, $args['term_id'] ); + if ( ! empty( $term->term_id ) ) + $query = $wpdb->prepare( "SELECT slug FROM $wpdb->terms WHERE slug = %s AND term_id != %d", $slug, $term->term_id ); else $query = $wpdb->prepare( "SELECT slug FROM $wpdb->terms WHERE slug = %s", $slug ); diff --git a/tests/tests/term.php b/tests/tests/term.php index 64dd1b4c30..e32894fbe1 100644 --- a/tests/tests/term.php +++ b/tests/tests/term.php @@ -373,8 +373,17 @@ class Tests_Term extends WP_UnitTestCase { $e = wp_insert_term( 'child-neighbor', $this->taxonomy, array( 'parent' => $c['term_id'] ) ); $this->assertEquals( 'child-neighbor-2', wp_unique_term_slug( 'child', $d_term ) ); + $f = wp_insert_term( 'foo', $this->taxonomy ); + $this->assertInternalType( 'array', $f ); + $f_term = get_term( $f['term_id'], $this->taxonomy ); + $this->assertEquals( 'foo', $f_term->slug ); + $this->assertEquals( 'foo', wp_unique_term_slug( 'foo', $f_term ) ); + + $g = wp_insert_term( 'foo', $this->taxonomy ); + $this->assertInstanceOf( 'WP_Error', $g ); + // clean up - foreach ( array( $a, $b, $c, $d, $e ) as $t ) + foreach ( array( $a, $b, $c, $d, $e, $f ) as $t ) $this->assertTrue( wp_delete_term( $t['term_id'], $this->taxonomy ) ); }