Changeset 5522
- Timestamp:
- 05/23/2007 05:42:31 AM (17 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/admin-db.php
r5510 r5522 290 290 return $id; 291 291 292 $tag_id = add_term($tag_name, 'post_tag');292 $tag_id = wp_insert_term($tag_name, 'post_tag'); 293 293 } 294 294 -
trunk/wp-includes/taxonomy.php
r5521 r5522 1 1 <?php 2 2 3 // TODO: add_term(), edit_term(), and remove_term() work with terms within context of4 // taxonomies. insert_term(), update_term(), delete_term() work with just the terms table.5 // insert_term_taxonomy(), update_term_taxonomy(), and delete_term_taxonomy() work6 // with just the term taxonomy table. Right now we only have add_term().7 8 3 /** 9 4 * Adds a new term to the database. Optionally marks it as an alias of an existing term. 10 * @param string $term The term to add.5 * @param int|string $term The term to add or update. 11 6 * @param string $taxonomy The taxonomy to which to add the term 12 7 * @param int|string $alias_of The id or slug of the new term's alias. 13 8 */ 14 function add_term( $term, $taxonomy, $args = array() ) { 15 global $wpdb; 16 17 $slug = sanitize_title($term); 18 $defaults = array( 'alias_of' => '', 'description' => '', 'parent' => 0); 9 function wp_insert_term( $term, $taxonomy, $args = array() ) { 10 global $wpdb; 11 12 $update = false; 13 if ( is_int($term) ) { 14 $update = true; 15 $term_id = $term; 16 } else { 17 $name = $term; 18 } 19 20 $defaults = array( 'alias_of' => '', 'description' => '', 'parent' => 0, 'slug' => ''); 19 21 $args = wp_parse_args($args, $defaults); 20 22 extract($args); 23 24 $parent = (int) $parent; 25 26 if ( empty($slug) ) 27 $slug = sanitize_title($name); 28 else 29 $slug = sanitize_title($slug); 21 30 22 31 $term_group = 0; … … 33 42 } 34 43 35 if ( ! $term_id = is_term($slug) ) { 36 $wpdb->query("INSERT INTO $wpdb->terms (name, slug, term_group) VALUES ('$term', '$slug', '$term_group')"); 44 if ( $update ) { 45 $wpdb->query("UPDATE $wpdb->terms SET name = '$name', slug = '$slug', term_group = '$term_group' WHERE term_id = '$term_id'"); 46 } else if ( ! $term_id = is_term($slug) ) { 47 $wpdb->query("INSERT INTO $wpdb->terms (name, slug, term_group) VALUES ('$name', '$slug', '$term_group')"); 37 48 $term_id = (int) $wpdb->insert_id; 38 49 } 39 50 51 if ( empty($slug) ) { 52 $slug = sanitize_title($slug, $term_id); 53 $wpdb->query("UPDATE $wpdb->terms SET slug = '$slug' WHERE term_id = '$term_id'"); 54 } 55 40 56 $tt_id = $wpdb->get_var("SELECT tt.term_taxonomy_id FROM $wpdb->term_taxonomy AS tt INNER JOIN $wpdb->terms AS t ON tt.term_id = t.term_id WHERE tt.taxonomy = '$taxonomy' AND t.term_id = $term_id"); 41 57 42 if ( !empty($tt_id) ) 43 return $term_id; 44 45 $wpdb->query("INSERT INTO $wpdb->term_taxonomy (term_id, taxonomy, description, parent, count) VALUES ('$term_id', '$taxonomy', '$description', '$parent', '0')"); 46 $tt_id = (int) $wpdb->insert_id; 58 if ( !$update && !empty($tt_id) ) 59 return array('term_id' => $term_id, 'term_taxonomy_id' => $tt_id); 60 61 if ( $update ) { 62 $wpdb->query("UPDATE $wpdb->term_taxonomy SET term_id = '$term_id', taxonomy = '$taxonomy', description = '$description', parent = '$parent', count = 0 WHERE term_taxonomy_id = '$tt_id'"); 63 } else { 64 $wpdb->query("INSERT INTO $wpdb->term_taxonomy (term_id, taxonomy, description, parent, count) VALUES ('$term_id', '$taxonomy', '$description', '$parent', '0')"); 65 $tt_id = (int) $wpdb->insert_id; 66 } 67 47 68 return array('term_id' => $term_id, 'term_taxonomy_id' => $tt_id); 48 69 } … … 51 72 * Removes a term from the database. 52 73 */ 53 function remove_term() {} 54 55 74 function wp_delete_term() {} 75 76 function wp_update_term( $term, $taxonomy, $fields = array() ) { 77 $term = (int) $term; 78 79 // First, get all of the original fields 80 $term = get_term ($term, $taxonomy, ARRAY_A); 81 82 // Escape data pulled from DB. 83 $term = add_magic_quotes($term); 84 85 // Merge old and new fields with new fields overwriting old ones. 86 $fields = array_merge($term, $fields); 87 88 return wp_insert_term($term, $taxonomy, $fields); 89 } 90 56 91 /** 57 92 * Returns the index of a defined term, or 0 (false) if the term doesn't exist. … … 120 155 foreach ($terms as $term) { 121 156 if ( !$id = is_term($term, $taxonomy) ) 122 $id = add_term($term, $taxonomy);157 $id = wp_insert_term($term, $taxonomy); 123 158 $id = $id['term_taxonomy_id']; 124 159 $tt_ids[] = $id;
Note: See TracChangeset
for help on using the changeset viewer.