Ticket #10012: custom_taxonomy_export.patch
| File custom_taxonomy_export.patch, 4.7 KB (added by chrisscott, 4 years ago) |
|---|
-
wp-admin/includes/export.php
24 24 * @param unknown_type $author 25 25 */ 26 26 function export_wp($author='') { 27 global $wpdb, $post_ids, $post ;27 global $wpdb, $post_ids, $post, $wp_taxonomies; 28 28 29 29 do_action('export_wp'); 30 30 … … 46 46 $categories = (array) get_categories('get=all'); 47 47 $tags = (array) get_tags('get=all'); 48 48 49 $custom_taxonomies = $wp_taxonomies; 50 unset($custom_taxonomies['category']); 51 unset($custom_taxonomies['post_tag']); 52 unset($custom_taxonomies['link_category']); 53 $custom_taxonomies = array_keys($custom_taxonomies); 54 $terms = (array) get_terms($custom_taxonomies, 'get=all'); 55 49 56 /** 50 57 * {@internal Missing Short Description}} 51 58 * … … 186 193 * {@internal Missing Short Description}} 187 194 * 188 195 * @since unknown 196 * 197 * @param object $t Term Object 189 198 */ 199 function wxr_term_name($t) { 200 if ( empty($t->name) ) 201 return; 202 203 echo '<wp:term_name>' . wxr_cdata($t->name) . '</wp:term_name>'; 204 } 205 206 /** 207 * {@internal Missing Short Description}} 208 * 209 * @since unknown 210 * 211 * @param object $t Term Object 212 */ 213 function wxr_term_description($t) { 214 if ( empty($t->description) ) 215 return; 216 217 echo '<wp:term_description>' . wxr_cdata($t->description) . '</wp:term_description>'; 218 } 219 220 /** 221 * {@internal Missing Short Description}} 222 * 223 * @since unknown 224 */ 190 225 function wxr_post_taxonomy() { 191 226 $categories = get_the_category(); 192 227 $tags = get_the_tags(); … … 256 291 <?php if ( $tags ) : foreach ( $tags as $t ) : ?> 257 292 <wp:tag><wp:tag_slug><?php echo $t->slug; ?></wp:tag_slug><?php wxr_tag_name($t); ?><?php wxr_tag_description($t); ?></wp:tag> 258 293 <?php endforeach; endif; ?> 294 <?php if ( $terms ) : foreach ( $terms as $t ) : ?> 295 <wp:term><wp:term_taxonomy><?php echo $t->taxonomy; ?></wp:term_taxonomy><wp:term_slug><?php echo $t->slug; ?></wp:term_slug><wp:term_parent><?php echo $t->parent ? $custom_taxonomies[$t->parent]->name : ''; ?></wp:term_parent><?php wxr_term_name($t); ?><?php wxr_term_description($t); ?></wp:term> 296 <?php endforeach; endif; ?> 259 297 <?php do_action('rss2_head'); ?> 260 298 <?php if ($post_ids) { 261 299 global $wp_query; -
wp-admin/import/wordpress.php
27 27 var $author_ids = array (); 28 28 var $tags = array (); 29 29 var $categories = array (); 30 var $terms = array (); 30 31 31 32 var $j = -1; 32 33 var $fetch_attachments = false; … … 122 123 $this->tags[] = $tag[1]; 123 124 continue; 124 125 } 126 if ( false !== strpos($importline, '<wp:term>') ) { 127 preg_match('|<wp:term>(.*?)</wp:term>|is', $importline, $term); 128 $this->terms[] = $term[1]; 129 continue; 130 } 125 131 if ( false !== strpos($importline, '<item>') ) { 126 132 $this->post = ''; 127 133 $doing_entry = true; … … 337 343 $tag_ID = wp_insert_term($tag_name, 'post_tag', $tagarr); 338 344 } 339 345 } 346 347 function process_terms() { 348 global $wpdb, $wp_taxonomies; 349 350 $custom_taxonomies = $wp_taxonomies; 351 // get rid of the standard taxonomies 352 unset( $custom_taxonomies['category'] ); 353 unset( $custom_taxonomies['post_tag'] ); 354 unset( $custom_taxonomies['link_category'] ); 355 356 $custom_taxonomies = array_keys( $custom_taxonomies ); 357 $current_terms = (array) get_terms( $custom_taxonomies, 'get=all' ); 358 $taxonomies = array(); 359 foreach ( $current_terms as $term ) { 360 if ( isset( $_terms[$term->taxonomy] ) ) { 361 $taxonomies[$term->taxonomy] = array_merge( $taxonomies[$term->taxonomy], array($term->name) ); 362 } else { 363 $taxonomies[$term->taxonomy] = array($term->name); 364 } 365 } 340 366 367 while ( $c = array_shift($this->terms) ) { 368 $term_name = trim($this->get_tag( $c, 'wp:term_name' )); 369 $term_taxonomy = trim($this->get_tag( $c, 'wp:term_taxonomy' )); 370 371 // If the term exists in the taxonomy we leave it alone 372 if ( isset($taxonomies[$term_taxonomy] ) && in_array( $term_name, $taxonomies[$term_taxonomy] ) ) 373 continue; 374 375 $slug = $this->get_tag( $c, 'wp:term_slug' ); 376 $description = $this->get_tag( $c, 'wp:term_description' ); 377 378 $termarr = compact('slug', 'description'); 379 380 $term_ID = wp_insert_term($term_name, $this->get_tag( $c, 'wp:term_taxonomy' ), $termarr); 381 } 382 } 383 341 384 function process_author($post) { 342 385 $author = $this->get_tag( $post, 'dc:creator' ); 343 386 if ($author) … … 748 791 $this->get_entries(); 749 792 $this->process_categories(); 750 793 $this->process_tags(); 794 $this->process_terms(); 751 795 $result = $this->process_posts(); 752 796 wp_suspend_cache_invalidation(false); 753 797 $this->backfill_parents();
