PHP Cross Reference of WordPress Subversion HEAD |
| [ Index ] [ Classes ] [ Functions ] [ Variables ] [ Constants ] |
[Summary view] [Print] [Text view]
1 <?php 2 3 // 4 // Category 5 // 6 7 function category_exists($cat_name) { 8 $id = is_term($cat_name, 'category'); 9 if ( is_array($id) ) 10 $id = $id['term_id']; 11 return $id; 12 } 13 14 function get_category_to_edit( $id ) { 15 $category = get_category( $id, OBJECT, 'edit' ); 16 return $category; 17 } 18 19 function wp_create_category($cat_name) { 20 if ( $id = category_exists($cat_name) ) 21 return $id; 22 23 return wp_insert_category( array('cat_name' => $cat_name) ); 24 } 25 26 function wp_create_categories($categories, $post_id = '') { 27 $cat_ids = array (); 28 foreach ($categories as $category) { 29 if ($id = category_exists($category)) 30 $cat_ids[] = $id; 31 else 32 if ($id = wp_create_category($category)) 33 $cat_ids[] = $id; 34 } 35 36 if ($post_id) 37 wp_set_post_categories($post_id, $cat_ids); 38 39 return $cat_ids; 40 } 41 42 function wp_delete_category($cat_ID) { 43 $cat_ID = (int) $cat_ID; 44 $default = get_option('default_category'); 45 46 // Don't delete the default cat 47 if ( $cat_ID == $default ) 48 return 0; 49 50 return wp_delete_term($cat_ID, 'category', "default=$default"); 51 } 52 53 function wp_insert_category($catarr, $wp_error = false) { 54 extract($catarr, EXTR_SKIP); 55 56 if ( trim( $cat_name ) == '' ) 57 return 0; 58 59 $cat_ID = (int) $cat_ID; 60 61 // Are we updating or creating? 62 if ( !empty ($cat_ID) ) 63 $update = true; 64 else 65 $update = false; 66 67 $name = $cat_name; 68 $description = $category_description; 69 $slug = $category_nicename; 70 $parent = $category_parent; 71 72 $parent = (int) $parent; 73 if ( empty($parent) || !category_exists( $parent ) || ($cat_ID && cat_is_ancestor_of($cat_ID, $parent) ) ) 74 $parent = 0; 75 76 $args = compact('name', 'slug', 'parent', 'description'); 77 78 if ( $update ) 79 $cat_ID = wp_update_term($cat_ID, 'category', $args); 80 else 81 $cat_ID = wp_insert_term($cat_name, 'category', $args); 82 83 if ( is_wp_error($cat_ID) ) { 84 if ( $wp_error ) 85 return $cat_ID; 86 else 87 return 0; 88 } 89 90 return $cat_ID['term_id']; 91 } 92 93 function wp_update_category($catarr) { 94 $cat_ID = (int) $catarr['cat_ID']; 95 96 if ( $cat_ID == $catarr['category_parent'] ) 97 return false; 98 99 // First, get all of the original fields 100 $category = get_category($cat_ID, ARRAY_A); 101 102 // Escape data pulled from DB. 103 $category = add_magic_quotes($category); 104 105 // Merge old and new fields with new fields overwriting old ones. 106 $catarr = array_merge($category, $catarr); 107 108 return wp_insert_category($catarr); 109 } 110 111 // 112 // Tags 113 // 114 115 function get_tags_to_edit( $post_id ) { 116 $post_id = (int) $post_id; 117 if ( !$post_id ) 118 return false; 119 120 $tags = wp_get_post_tags($post_id); 121 122 if ( !$tags ) 123 return false; 124 125 foreach ( $tags as $tag ) 126 $tag_names[] = $tag->name; 127 $tags_to_edit = join( ', ', $tag_names ); 128 $tags_to_edit = attribute_escape( $tags_to_edit ); 129 $tags_to_edit = apply_filters( 'tags_to_edit', $tags_to_edit ); 130 return $tags_to_edit; 131 } 132 133 function tag_exists($tag_name) { 134 return is_term($tag_name, 'post_tag'); 135 } 136 137 function wp_create_tag($tag_name) { 138 if ( $id = tag_exists($tag_name) ) 139 return $id; 140 141 return wp_insert_term($tag_name, 'post_tag'); 142 } 143 144 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated Thu Dec 6 06:47:08 2007 for RedAlt XRefs | Cross-referenced by PHPXref 0.6 and RedAlt |