Prepare DB queries in more places. Props filosofo. see #6644

git-svn-id: https://develop.svn.wordpress.org/trunk@7645 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan Boren
2008-04-14 16:13:25 +00:00
parent 32e9822516
commit fdc05b24f6
24 changed files with 153 additions and 166 deletions
+4 -5
View File
@@ -749,7 +749,7 @@ function is_term($term, $taxonomy = '') {
}
if ( !empty($taxonomy) )
return $wpdb->get_row("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 = '$taxonomy'", ARRAY_A);
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);
return $wpdb->get_var("SELECT term_id FROM $wpdb->terms as t WHERE $where");
}
@@ -888,8 +888,7 @@ function wp_count_terms( $taxonomy, $args = array() ) {
if ( $ignore_empty )
$where = 'AND count > 0';
$taxonomy = $wpdb->escape( $taxonomy );
return $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->term_taxonomy WHERE taxonomy = '$taxonomy' $where");
return $wpdb->get_var( $wpdb->prepare("SELECT COUNT(*) FROM $wpdb->term_taxonomy WHERE taxonomy = %s $where", $taxonomy) );
}
/**
@@ -918,7 +917,7 @@ function wp_delete_object_term_relationships( $object_id, $taxonomies ) {
foreach ( $taxonomies as $taxonomy ) {
$terms = wp_get_object_terms($object_id, $taxonomy, 'fields=tt_ids');
$in_terms = "'" . implode("', '", $terms) . "'";
$wpdb->query("DELETE FROM $wpdb->term_relationships WHERE object_id = '$object_id' AND term_taxonomy_id IN ($in_terms)");
$wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->term_relationships WHERE object_id = %d AND term_taxonomy_id IN ($in_terms)", $object_id) );
wp_update_term_count($terms, $taxonomy);
}
}
@@ -1293,7 +1292,7 @@ function wp_set_object_terms($object_id, $terms, $taxonomy, $append = false) {
$delete_terms = array_diff($old_terms, $tt_ids);
if ( $delete_terms ) {
$in_delete_terms = "'" . implode("', '", $delete_terms) . "'";
$wpdb->query("DELETE FROM $wpdb->term_relationships WHERE object_id = '$object_id' AND term_taxonomy_id IN ($in_delete_terms)");
$wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->term_relationships WHERE object_id = %d AND term_taxonomy_id IN ($in_delete_terms)", $object_id) );
wp_update_term_count($delete_terms, $taxonomy);
}
}