diff options
Diffstat (limited to 'wp-includes/taxonomy.php')
-rw-r--r-- | wp-includes/taxonomy.php | 38 |
1 files changed, 30 insertions, 8 deletions
diff --git a/wp-includes/taxonomy.php b/wp-includes/taxonomy.php index 6c6edea..b3011f3 100644 --- a/wp-includes/taxonomy.php +++ b/wp-includes/taxonomy.php @@ -761,20 +761,36 @@ function &get_terms($taxonomies, $args = '') { function is_term($term, $taxonomy = '') { global $wpdb; + $select = "SELECT term_id FROM $wpdb->terms as t WHERE "; + $tax_select = "SELECT tt.term_id, tt.term_taxonomy_id FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy as tt ON tt.term_id = t.term_id WHERE "; + if ( is_int($term) ) { if ( 0 == $term ) return 0; - $where = $wpdb->prepare( "t.term_id = %d", $term ); - } else { - if ( '' === $term = sanitize_title($term) ) - return 0; - $where = $wpdb->prepare( "t.slug = %s", $term ); + $where = 't.term_id = %d'; + if ( !empty($taxonomy) ) + return $wpdb->get_row( $wpdb->prepare( $tax_select . $where . " AND tt.taxonomy = %s", $term, $taxonomy ), ARRAY_A ); + else + return $wpdb->get_var( $wpdb->prepare( $select . $where, $term ) ); + } + + if ( '' === $slug = sanitize_title($term) ) + return 0; + + $where = 't.slug = %s'; + $else_where = 't.name = %s'; + + if ( !empty($taxonomy) ) { + if ( $result = $wpdb->get_row( $wpdb->prepare("SELECT tt.term_id, tt.term_taxonomy_id FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy as tt ON tt.term_id = t.term_id WHERE $where AND tt.taxonomy = %s", $slug, $taxonomy), ARRAY_A) ) + return $result; + + return $wpdb->get_row( $wpdb->prepare("SELECT tt.term_id, tt.term_taxonomy_id FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy as tt ON tt.term_id = t.term_id WHERE $else_where AND tt.taxonomy = %s", $term, $taxonomy), ARRAY_A); } - if ( !empty($taxonomy) ) - return $wpdb->get_row( $wpdb->prepare("SELECT tt.term_id, tt.term_taxonomy_id FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy as tt ON tt.term_id = t.term_id WHERE $where AND tt.taxonomy = %s", $taxonomy), ARRAY_A); + if ( $result = $wpdb->get_var( $wpdb->prepare("SELECT term_id FROM $wpdb->terms as t WHERE $where", $slug) ) ) + return $result; - return $wpdb->get_var("SELECT term_id FROM $wpdb->terms as t WHERE $where"); + return $wpdb->get_var( $wpdb->prepare("SELECT term_id FROM $wpdb->terms as t WHERE $else_where", $term) ); } /** @@ -1199,6 +1215,9 @@ function wp_insert_term( $term, $taxonomy, $args = array() ) { if ( is_int($term) && 0 == $term ) return new WP_Error('invalid_term_id', __('Invalid term ID')); + if ( '' == trim($term) ) + return new WP_Error('empty_term_name', __('A name is required for this term')); + $defaults = array( 'alias_of' => '', 'description' => '', 'parent' => 0, 'slug' => ''); $args = wp_parse_args($args, $defaults); $args['name'] = $term; @@ -1472,6 +1491,9 @@ function wp_update_term( $term, $taxonomy, $args = array() ) { $name = stripslashes($name); $description = stripslashes($description); + if ( '' == trim($name) ) + return new WP_Error('empty_term_name', __('A name is required for this term')); + $empty_slug = false; if ( empty($slug) ) { $empty_slug = true; |