Make WordPress Core

Ticket #29851: 29851.patch

File 29851.patch, 2.3 KB (added by boonebgorges, 12 years ago)
  • src/wp-includes/taxonomy.php

    diff --git src/wp-includes/taxonomy.php src/wp-includes/taxonomy.php
    index 5846844..0c12c4c 100644
    function get_terms( $taxonomies, $args = '' ) { 
    16541654 *
    16551655 * @param int|string $term The term to check
    16561656 * @param string $taxonomy The taxonomy name to use
    1657  * @param int $parent ID of parent term under which to confine the exists search.
     1657 * @param int $parent Optional. ID of parent term under which to confine the exists search.
    16581658 * @return mixed Returns 0 if the term does not exist. Returns the term ID if no taxonomy is specified
    16591659 *               and the term ID exists. Returns an array of the term ID and the term taxonomy ID
    16601660 *               if the taxonomy is specified and the pairing exists.
    16611661 */
    1662 function term_exists($term, $taxonomy = '', $parent = 0) {
     1662function term_exists( $term, $taxonomy = '', $parent = null ) {
    16631663        global $wpdb;
    16641664
    16651665        $select = "SELECT term_id FROM $wpdb->terms as t WHERE ";
    function term_exists($term, $taxonomy = '', $parent = 0) { 
    16851685        $where_fields = array($slug);
    16861686        $else_where_fields = array($term);
    16871687        if ( !empty($taxonomy) ) {
    1688                 $parent = (int) $parent;
    1689                 if ( $parent > 0 ) {
     1688                if ( is_numeric( $parent ) ) {
     1689                        $parent = (int) $parent;
    16901690                        $where_fields[] = $parent;
    16911691                        $else_where_fields[] = $parent;
    16921692                        $where .= ' AND tt.parent = %d';
  • tests/phpunit/tests/term.php

    diff --git tests/phpunit/tests/term.php tests/phpunit/tests/term.php
    index 180e87d..c9bd074 100644
    class Tests_Term extends WP_UnitTestCase { 
    138138                $this->assertEquals( $t, $found['term_id'] );
    139139        }
    140140
     141        public function test_term_exists_taxonomy_nonempty_parent_0_should_return_false_for_child_term() {
     142                register_taxonomy( 'foo', 'post', array(
     143                        'hierarchical' => true,
     144                ) );
     145
     146                $parent_term = $this->factory->term->create( array(
     147                        'taxonomy' => 'foo',
     148                ) );
     149
     150                $t = $this->factory->term->create( array(
     151                        'taxonomy' => 'foo',
     152                        'parent' => $parent_term,
     153                        'slug' => 'child-term',
     154                ) );
     155
     156                $found = term_exists( 'child-term', 'foo', 0 );
     157
     158                _unregister_taxonomy( 'foo' );
     159
     160                $this->assertSame( null, $found['term_id'] );
     161        }
     162
    141163        public function test_term_exists_taxonomy_nonempty_parent_nonempty_match_name() {
    142164                register_taxonomy( 'foo', 'post', array(
    143165                        'hierarchical' => true,