Check both slug and name when determining if is_term(). fixes #6593 for trunk

git-svn-id: http://svn.automattic.com/wordpress/trunk@8433 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2008-07-24 19:28:40 +00:00
parent 07b7e7b7a4
commit e8cba9f0cb
3 changed files with 26 additions and 9 deletions

View File

@ -19,7 +19,8 @@ $wp_queries="CREATE TABLE $wpdb->terms (
slug varchar(200) NOT NULL default '',
term_group bigint(10) NOT NULL default 0,
PRIMARY KEY (term_id),
UNIQUE KEY slug (slug)
UNIQUE KEY slug (slug),
KEY name (name)
) $charset_collate;
CREATE TABLE $wpdb->term_taxonomy (
term_taxonomy_id bigint(20) NOT NULL auto_increment,

View File

@ -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 = 't.term_id = %d';
} else {
if ( '' === $term = sanitize_title($term) )
return 0;
$where = 't.slug = %s';
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 ( !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", $term, $taxonomy), ARRAY_A);
if ( '' === $slug = sanitize_title($term) )
return 0;
return $wpdb->get_var( $wpdb->prepare("SELECT term_id FROM $wpdb->terms as t WHERE $where", $term) );
$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 ( $result = $wpdb->get_var( $wpdb->prepare("SELECT term_id FROM $wpdb->terms as t WHERE $where", $slug) ) )
return $result;
return $wpdb->get_var( $wpdb->prepare("SELECT term_id FROM $wpdb->terms as t WHERE $else_where", $term) );
}
/**

View File

@ -15,6 +15,6 @@ $wp_version = '2.7-bleeding';
*
* @global int $wp_db_version
*/
$wp_db_version = 8202;
$wp_db_version = 8370;
?>