Changeset 42343 for trunk/src/wp-admin/includes/taxonomy.php
- Timestamp:
- 11/30/2017 11:09:33 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/taxonomy.php
r37573 r42343 23 23 */ 24 24 function category_exists( $cat_name, $parent = null ) { 25 $id = term_exists( $cat_name, 'category', $parent);26 if ( is_array( $id) )25 $id = term_exists( $cat_name, 'category', $parent ); 26 if ( is_array( $id ) ) { 27 27 $id = $id['term_id']; 28 } 28 29 return $id; 29 30 } … … 53 54 */ 54 55 function wp_create_category( $cat_name, $parent = 0 ) { 55 if ( $id = category_exists( $cat_name, $parent) )56 if ( $id = category_exists( $cat_name, $parent ) ) { 56 57 return $id; 57 58 return wp_insert_category( array('cat_name' => $cat_name, 'category_parent' => $parent) ); 58 } 59 60 return wp_insert_category( 61 array( 62 'cat_name' => $cat_name, 63 'category_parent' => $parent, 64 ) 65 ); 59 66 } 60 67 … … 69 76 */ 70 77 function wp_create_categories( $categories, $post_id = '' ) { 71 $cat_ids = array 78 $cat_ids = array(); 72 79 foreach ( $categories as $category ) { 73 80 if ( $id = category_exists( $category ) ) { … … 78 85 } 79 86 80 if ( $post_id ) 81 wp_set_post_categories($post_id, $cat_ids); 87 if ( $post_id ) { 88 wp_set_post_categories( $post_id, $cat_ids ); 89 } 82 90 83 91 return $cat_ids; … … 107 115 */ 108 116 function wp_insert_category( $catarr, $wp_error = false ) { 109 $cat_defaults = array( 'cat_ID' => 0, 'taxonomy' => 'category', 'cat_name' => '', 'category_description' => '', 'category_nicename' => '', 'category_parent' => '' ); 110 $catarr = wp_parse_args( $catarr, $cat_defaults ); 117 $cat_defaults = array( 118 'cat_ID' => 0, 119 'taxonomy' => 'category', 120 'cat_name' => '', 121 'category_description' => '', 122 'category_nicename' => '', 123 'category_parent' => '', 124 ); 125 $catarr = wp_parse_args( $catarr, $cat_defaults ); 111 126 112 127 if ( trim( $catarr['cat_name'] ) == '' ) { … … 121 136 122 137 // Are we updating or creating? 123 $update = ! empty 124 125 $name = $catarr['cat_name'];138 $update = ! empty( $catarr['cat_ID'] ); 139 140 $name = $catarr['cat_name']; 126 141 $description = $catarr['category_description']; 127 $slug = $catarr['category_nicename'];128 $parent = (int) $catarr['category_parent'];142 $slug = $catarr['category_nicename']; 143 $parent = (int) $catarr['category_parent']; 129 144 if ( $parent < 0 ) { 130 145 $parent = 0; … … 137 152 } 138 153 139 $args = compact( 'name', 'slug', 'parent', 'description');154 $args = compact( 'name', 'slug', 'parent', 'description' ); 140 155 141 156 if ( $update ) { … … 166 181 * @return int|bool The ID number of the new or updated Category on success. Zero or FALSE on failure. 167 182 */ 168 function wp_update_category( $catarr) {183 function wp_update_category( $catarr ) { 169 184 $cat_ID = (int) $catarr['cat_ID']; 170 185 171 if ( isset( $catarr['category_parent']) && ($cat_ID == $catarr['category_parent']) )186 if ( isset( $catarr['category_parent'] ) && ( $cat_ID == $catarr['category_parent'] ) ) { 172 187 return false; 188 } 173 189 174 190 // First, get all of the original fields … … 177 193 178 194 // Escape data pulled from DB. 179 $category = wp_slash( $category);195 $category = wp_slash( $category ); 180 196 181 197 // Merge old and new fields with new fields overwriting old ones. 182 $catarr = array_merge( $category, $catarr);183 184 return wp_insert_category( $catarr);198 $catarr = array_merge( $category, $catarr ); 199 200 return wp_insert_category( $catarr ); 185 201 } 186 202 … … 197 213 * @return mixed 198 214 */ 199 function tag_exists( $tag_name) {200 return term_exists( $tag_name, 'post_tag');215 function tag_exists( $tag_name ) { 216 return term_exists( $tag_name, 'post_tag' ); 201 217 } 202 218 … … 209 225 * @return array|WP_Error 210 226 */ 211 function wp_create_tag( $tag_name) {212 return wp_create_term( $tag_name, 'post_tag' );227 function wp_create_tag( $tag_name ) { 228 return wp_create_term( $tag_name, 'post_tag' ); 213 229 } 214 230 … … 223 239 */ 224 240 function get_tags_to_edit( $post_id, $taxonomy = 'post_tag' ) { 225 return get_terms_to_edit( $post_id, $taxonomy );241 return get_terms_to_edit( $post_id, $taxonomy ); 226 242 } 227 243 … … 237 253 function get_terms_to_edit( $post_id, $taxonomy = 'post_tag' ) { 238 254 $post_id = (int) $post_id; 239 if ( ! $post_id )255 if ( ! $post_id ) { 240 256 return false; 257 } 241 258 242 259 $terms = get_object_term_cache( $post_id, $taxonomy ); … … 283 300 * @return array|WP_Error 284 301 */ 285 function wp_create_term( $tag_name, $taxonomy = 'post_tag') {286 if ( $id = term_exists( $tag_name, $taxonomy) )302 function wp_create_term( $tag_name, $taxonomy = 'post_tag' ) { 303 if ( $id = term_exists( $tag_name, $taxonomy ) ) { 287 304 return $id; 288 289 return wp_insert_term($tag_name, $taxonomy); 290 } 305 } 306 307 return wp_insert_term( $tag_name, $taxonomy ); 308 }
Note: See TracChangeset
for help on using the changeset viewer.