7 function category_exists($cat_name) {
8 $id = is_term($cat_name, 'category');
14 function get_category_to_edit( $id ) {
15 $category = get_category( $id, OBJECT, 'edit' );
19 function wp_create_category($cat_name) {
20 if ( $id = category_exists($cat_name) )
23 return wp_insert_category( array('cat_name' => $cat_name) );
26 function wp_create_categories($categories, $post_id = '') {
28 foreach ($categories as $category) {
29 if ($id = category_exists($category))
32 if ($id = wp_create_category($category))
37 wp_set_post_categories($post_id, $cat_ids);
42 function wp_delete_category($cat_ID) {
45 $cat_ID = (int) $cat_ID;
46 $default = get_option('default_category');
48 // Don't delete the default cat
49 if ( $cat_ID == $default )
52 return wp_delete_term($cat_ID, 'category', "default=$default");
55 function wp_insert_category($catarr) {
58 extract($catarr, EXTR_SKIP);
60 if ( trim( $cat_name ) == '' )
63 $cat_ID = (int) $cat_ID;
65 // Are we updating or creating?
66 if ( !empty ($cat_ID) )
72 $description = $category_description;
73 $slug = $category_nicename;
74 $parent = $category_parent;
76 $parent = (int) $parent;
77 if ( empty($parent) || !category_exists( $parent ) || ($cat_ID && cat_is_ancestor_of($cat_ID, $parent) ) )
80 $args = compact('name', 'slug', 'parent', 'description');
83 $cat_ID = wp_update_term($cat_ID, 'category', $args);
85 $cat_ID = wp_insert_term($cat_name, 'category', $args);
87 if ( is_wp_error($cat_ID) )
90 return $cat_ID['term_id'];
93 function wp_update_category($catarr) {
96 $cat_ID = (int) $catarr['cat_ID'];
98 if ( $cat_ID == $catarr['category_parent'] )
101 // First, get all of the original fields
102 $category = get_category($cat_ID, ARRAY_A);
104 // Escape data pulled from DB.
105 $category = add_magic_quotes($category);
107 // Merge old and new fields with new fields overwriting old ones.
108 $catarr = array_merge($category, $catarr);
110 return wp_insert_category($catarr);
117 function get_tags_to_edit( $post_id ) {
120 $post_id = (int) $post_id;
124 $tags = wp_get_post_tags($post_id);
129 foreach ( $tags as $tag )
130 $tag_names[] = $tag->name;
131 $tags_to_edit = join( ', ', $tag_names );
132 $tags_to_edit = attribute_escape( $tags_to_edit );
133 $tags_to_edit = apply_filters( 'tags_to_edit', $tags_to_edit );
134 return $tags_to_edit;
137 function tag_exists($tag_name) {
138 return is_term($tag_name, 'post_tag');
141 function wp_create_tag($tag_name) {
142 if ( $id = tag_exists($tag_name) )
145 return wp_insert_term($tag_name, 'post_tag');