Ticket #34062: 34062-wordpress-importer.diff
File 34062-wordpress-importer.diff, 4.7 KB (added by , 8 years ago) |
---|
-
parsers.php
114 114 // grab cats, tags and terms 115 115 foreach ( $xml->xpath('/rss/channel/wp:category') as $term_arr ) { 116 116 $t = $term_arr->children( $namespaces['wp'] ); 117 $categor ies[]= array(117 $category = array( 118 118 'term_id' => (int) $t->term_id, 119 119 'category_nicename' => (string) $t->category_nicename, 120 120 'category_parent' => (string) $t->category_parent, … … 121 121 'cat_name' => (string) $t->cat_name, 122 122 'category_description' => (string) $t->category_description 123 123 ); 124 125 foreach ( $t->termmeta as $meta ) { 126 $category['termmeta'][] = array( 127 'key' => (string) $meta->meta_key, 128 'value' => (string) $meta->meta_value 129 ); 130 } 131 132 $categories[] = $category; 124 133 } 125 134 126 135 foreach ( $xml->xpath('/rss/channel/wp:tag') as $term_arr ) { 127 136 $t = $term_arr->children( $namespaces['wp'] ); 128 $tag s[]= array(137 $tag = array( 129 138 'term_id' => (int) $t->term_id, 130 139 'tag_slug' => (string) $t->tag_slug, 131 140 'tag_name' => (string) $t->tag_name, 132 141 'tag_description' => (string) $t->tag_description 133 142 ); 143 144 foreach ( $t->termmeta as $meta ) { 145 $tag['termmeta'][] = array( 146 'key' => (string) $meta->meta_key, 147 'value' => (string) $meta->meta_value 148 ); 149 } 150 151 $tags[] = $tag; 134 152 } 135 153 136 154 foreach ( $xml->xpath('/rss/channel/wp:term') as $term_arr ) { 137 155 $t = $term_arr->children( $namespaces['wp'] ); 138 $term s[]= array(156 $term = array( 139 157 'term_id' => (int) $t->term_id, 140 158 'term_taxonomy' => (string) $t->term_taxonomy, 141 159 'slug' => (string) $t->term_slug, … … 143 161 'term_name' => (string) $t->term_name, 144 162 'term_description' => (string) $t->term_description 145 163 ); 164 165 foreach ( $t->termmeta as $meta ) { 166 $term['termmeta'][] = array( 167 'key' => (string) $meta->meta_key, 168 'value' => (string) $meta->meta_value 169 ); 170 } 171 172 $terms[] = $term; 146 173 } 147 174 148 175 // grab posts … … 204 231 ); 205 232 } 206 233 } 207 234 208 235 $post['comments'][] = array( 209 236 'comment_id' => (int) $comment->comment_id, 210 237 'comment_author' => (string) $comment->comment_author, -
wordpress-importer.php
426 426 echo '<br />'; 427 427 continue; 428 428 } 429 430 $this->process_termmeta( $cat, $id['term_id'] ); 429 431 } 430 432 431 433 unset( $this->categories ); … … 466 468 echo '<br />'; 467 469 continue; 468 470 } 471 472 $this->process_termmeta( $tag, $id['term_id'] ); 469 473 } 470 474 471 475 unset( $this->tags ); … … 512 516 echo '<br />'; 513 517 continue; 514 518 } 519 520 $this->process_termmeta( $term, $id['term_id'] ); 515 521 } 516 522 517 523 unset( $this->terms ); … … 518 524 } 519 525 520 526 /** 527 * Add metadata to imported term. 528 * 529 * @since 0.6.2 530 * 531 * @param array $term Term data from WXR import. 532 * @param int $term_id ID of the newly created term. 533 */ 534 protected function process_termmeta( $term, $term_id ) { 535 if ( ! isset( $term['termmeta'] ) ) { 536 $term['termmeta'] = array(); 537 } 538 539 /** 540 * Filters the metadata attached to an imported term. 541 * 542 * @since 0.6.2 543 * 544 * @param array $termmeta Array of term meta. 545 * @param int $term_id ID of the newly created term. 546 * @param array $term Term data from the WXR import. 547 */ 548 $term['termmeta'] = apply_filters( 'wp_import_term_meta', $term['termmeta'], $term_id, $term ); 549 550 if ( ! empty( $term['termmeta'] ) ) { 551 foreach ( $term['termmeta'] as $meta ) { 552 /** 553 * Filters the meta key for an imported piece of term meta. 554 * 555 * @since 0.6.2 556 * 557 * @param string $meta_key Meta key. 558 * @param int $term_id ID of the newly created term. 559 * @param array $term Term data from the WXR import. 560 */ 561 $key = apply_filters( 'import_term_meta_key', $meta['key'], $term_id, $term ); 562 563 if ( $key ) { 564 // Export gets meta straight from the DB so could have a serialized string 565 $value = maybe_unserialize( $meta['value'] ); 566 567 add_term_meta( $term_id, $key, $value ); 568 569 /** 570 * Fires after term meta is imported. 571 * 572 * @since 0.6.2 573 * 574 * @param int $term_id ID of the newly created term. 575 * @param string $key Meta key. 576 * @param mixed $value Meta value. 577 */ 578 do_action( 'import_term_meta', $term_id, $key, $value ); 579 } 580 } 581 } 582 } 583 584 /** 521 585 * Create new posts based on import information 522 586 * 523 587 * Posts marked as having a parent which doesn't exist will become top level items.