Fix term_exists() for parent = 0.

Passing a 0 (or '0') as the 'parent' param of term_exists() should limit
results to terms with no parent.

Adds unit test.

Fixes #29851.
Built from https://develop.svn.wordpress.org/trunk@29863


git-svn-id: http://core.svn.wordpress.org/trunk@29623 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Boone Gorges 2014-10-09 02:49:18 +00:00
parent 3ceee6cd24
commit 61317341eb

View File

@ -1655,12 +1655,12 @@ function get_terms( $taxonomies, $args = '' ) {
*
* @param int|string $term The term to check
* @param string $taxonomy The taxonomy name to use
* @param int $parent ID of parent term under which to confine the exists search.
* @param int $parent Optional. ID of parent term under which to confine the exists search.
* @return mixed Returns 0 if the term does not exist. Returns the term ID if no taxonomy is specified
* and the term ID exists. Returns an array of the term ID and the term taxonomy ID
* if the taxonomy is specified and the pairing exists.
*/
function term_exists($term, $taxonomy = '', $parent = 0) {
function term_exists( $term, $taxonomy = '', $parent = null ) {
global $wpdb;
$select = "SELECT term_id FROM $wpdb->terms as t WHERE ";
@ -1686,8 +1686,8 @@ function term_exists($term, $taxonomy = '', $parent = 0) {
$where_fields = array($slug);
$else_where_fields = array($term);
if ( !empty($taxonomy) ) {
$parent = (int) $parent;
if ( $parent > 0 ) {
if ( is_numeric( $parent ) ) {
$parent = (int) $parent;
$where_fields[] = $parent;
$else_where_fields[] = $parent;
$where .= ' AND tt.parent = %d';