diff --git src/wp-includes/taxonomy.php src/wp-includes/taxonomy.php
index 5846844..0c12c4c 100644
|
|
|
function get_terms( $taxonomies, $args = '' ) { |
| 1654 | 1654 | * |
| 1655 | 1655 | * @param int|string $term The term to check |
| 1656 | 1656 | * @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. |
| 1658 | 1658 | * @return mixed Returns 0 if the term does not exist. Returns the term ID if no taxonomy is specified |
| 1659 | 1659 | * and the term ID exists. Returns an array of the term ID and the term taxonomy ID |
| 1660 | 1660 | * if the taxonomy is specified and the pairing exists. |
| 1661 | 1661 | */ |
| 1662 | | function term_exists($term, $taxonomy = '', $parent = 0) { |
| | 1662 | function term_exists( $term, $taxonomy = '', $parent = null ) { |
| 1663 | 1663 | global $wpdb; |
| 1664 | 1664 | |
| 1665 | 1665 | $select = "SELECT term_id FROM $wpdb->terms as t WHERE "; |
| … |
… |
function term_exists($term, $taxonomy = '', $parent = 0) { |
| 1685 | 1685 | $where_fields = array($slug); |
| 1686 | 1686 | $else_where_fields = array($term); |
| 1687 | 1687 | if ( !empty($taxonomy) ) { |
| 1688 | | $parent = (int) $parent; |
| 1689 | | if ( $parent > 0 ) { |
| | 1688 | if ( is_numeric( $parent ) ) { |
| | 1689 | $parent = (int) $parent; |
| 1690 | 1690 | $where_fields[] = $parent; |
| 1691 | 1691 | $else_where_fields[] = $parent; |
| 1692 | 1692 | $where .= ' AND tt.parent = %d'; |
diff --git tests/phpunit/tests/term.php tests/phpunit/tests/term.php
index 180e87d..c9bd074 100644
|
|
|
class Tests_Term extends WP_UnitTestCase { |
| 138 | 138 | $this->assertEquals( $t, $found['term_id'] ); |
| 139 | 139 | } |
| 140 | 140 | |
| | 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 | |
| 141 | 163 | public function test_term_exists_taxonomy_nonempty_parent_nonempty_match_name() { |
| 142 | 164 | register_taxonomy( 'foo', 'post', array( |
| 143 | 165 | 'hierarchical' => true, |