WordPress Importer - Version 0.6.1

Version Description

= 0.6 = Support for exports from WordPress 3.4.

= 0.5.2 = Fix incorrect error message when the export file could not be uploaded.

= 0.5 = Import comment meta and other minor bugfixes and enhancements.

= 0.4 = Bug fixes for attachment importing and other small enhancements.

= 0.3 = Upgrade for a more robust and reliable experience when importing WordPress export files, and for compatibility with WordPress 3.1.

Download this release

Release Info

Developer Otto42
Plugin Icon 128x128 WordPress Importer
Version 0.6.1
Comparing to
See all releases

Code changes from version 0.6 to 0.6.1

Files changed (3) hide show
  1. parsers.php +18 -1
  2. readme.txt +5 -3
  3. wordpress-importer.php +37 -3
parsers.php CHANGED
@@ -57,7 +57,24 @@ class WXR_Parser_SimpleXML {
57
  $authors = $posts = $categories = $tags = $terms = array();
58
 
59
  $internal_errors = libxml_use_internal_errors(true);
60
- $xml = simplexml_load_file( $file );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
  // halt if loading produces an error
62
  if ( ! $xml )
63
  return new WP_Error( 'SimpleXML_parse_error', __( 'There was an error when reading this WXR file', 'wordpress-importer' ), libxml_get_errors() );
57
  $authors = $posts = $categories = $tags = $terms = array();
58
 
59
  $internal_errors = libxml_use_internal_errors(true);
60
+
61
+ $dom = new DOMDocument;
62
+ $old_value = null;
63
+ if ( function_exists( 'libxml_disable_entity_loader' ) ) {
64
+ $old_value = libxml_disable_entity_loader( true );
65
+ }
66
+ $success = $dom->loadXML( file_get_contents( $file ) );
67
+ if ( ! is_null( $old_value ) ) {
68
+ libxml_disable_entity_loader( $old_value );
69
+ }
70
+
71
+ if ( ! $success || isset( $dom->doctype ) ) {
72
+ return new WP_Error( 'SimpleXML_parse_error', __( 'There was an error when reading this WXR file', 'wordpress-importer' ), libxml_get_errors() );
73
+ }
74
+
75
+ $xml = simplexml_import_dom( $dom );
76
+ unset( $dom );
77
+
78
  // halt if loading produces an error
79
  if ( ! $xml )
80
  return new WP_Error( 'SimpleXML_parse_error', __( 'There was an error when reading this WXR file', 'wordpress-importer' ), libxml_get_errors() );
readme.txt CHANGED
@@ -1,10 +1,12 @@
1
- === Plugin Name ===
2
  Contributors: wordpressdotorg
3
  Donate link:
4
  Tags: importer, wordpress
5
  Requires at least: 3.0
6
- Tested up to: 3.4
7
- Stable tag: 0.6
 
 
8
 
9
  Import posts, pages, comments, custom fields, categories, tags and more from a WordPress export file.
10
 
1
+ === WordPress Importer ===
2
  Contributors: wordpressdotorg
3
  Donate link:
4
  Tags: importer, wordpress
5
  Requires at least: 3.0
6
+ Tested up to: 4.3
7
+ Stable tag: 0.6.1
8
+ License: GPLv2 or later
9
+ License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
11
  Import posts, pages, comments, custom fields, categories, tags and more from a WordPress export file.
12
 
wordpress-importer.php CHANGED
@@ -5,7 +5,7 @@ Plugin URI: http://wordpress.org/extend/plugins/wordpress-importer/
5
  Description: Import posts, pages, comments, custom fields, categories, tags and more from a WordPress export file.
6
  Author: wordpressdotorg
7
  Author URI: http://wordpress.org/
8
- Version: 0.6
9
  Text Domain: wordpress-importer
10
  License: GPL version 2 or later - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
11
  */
@@ -393,6 +393,8 @@ class WP_Import extends WP_Importer {
393
  * Doesn't create a new category if its slug already exists
394
  */
395
  function process_categories() {
 
 
396
  if ( empty( $this->categories ) )
397
  return;
398
 
@@ -437,6 +439,8 @@ class WP_Import extends WP_Importer {
437
  * Doesn't create a tag if its slug already exists
438
  */
439
  function process_tags() {
 
 
440
  if ( empty( $this->tags ) )
441
  return;
442
 
@@ -475,6 +479,8 @@ class WP_Import extends WP_Importer {
475
  * Doesn't create a term its slug already exists
476
  */
477
  function process_terms() {
 
 
478
  if ( empty( $this->terms ) )
479
  return;
480
 
@@ -522,11 +528,16 @@ class WP_Import extends WP_Importer {
522
  * Note that new/updated terms, comments and meta are imported for the last of the above.
523
  */
524
  function process_posts() {
 
 
525
  foreach ( $this->posts as $post ) {
 
 
526
  if ( ! post_type_exists( $post['post_type'] ) ) {
527
  printf( __( 'Failed to import “%s”: Invalid post type %s', 'wordpress-importer' ),
528
  esc_html($post['post_title']), esc_html($post['post_type']) );
529
  echo '<br />';
 
530
  continue;
531
  }
532
 
@@ -578,6 +589,9 @@ class WP_Import extends WP_Importer {
578
  'post_type' => $post['post_type'], 'post_password' => $post['post_password']
579
  );
580
 
 
 
 
581
  if ( 'attachment' == $postdata['post_type'] ) {
582
  $remote_url = ! empty($post['attachment_url']) ? $post['attachment_url'] : $post['guid'];
583
 
@@ -597,6 +611,7 @@ class WP_Import extends WP_Importer {
597
  $comment_post_ID = $post_id = $this->process_attachment( $postdata, $remote_url );
598
  } else {
599
  $comment_post_ID = $post_id = wp_insert_post( $postdata, true );
 
600
  }
601
 
602
  if ( is_wp_error( $post_id ) ) {
@@ -615,6 +630,11 @@ class WP_Import extends WP_Importer {
615
  // map pre-import ID to local ID
616
  $this->processed_posts[intval($post['post_id'])] = (int) $post_id;
617
 
 
 
 
 
 
618
  // add categories, tags and other terms
619
  if ( ! empty( $post['terms'] ) ) {
620
  $terms_to_set = array();
@@ -627,11 +647,13 @@ class WP_Import extends WP_Importer {
627
  $t = wp_insert_term( $term['name'], $taxonomy, array( 'slug' => $term['slug'] ) );
628
  if ( ! is_wp_error( $t ) ) {
629
  $term_id = $t['term_id'];
 
630
  } else {
631
  printf( __( 'Failed to import %s %s', 'wordpress-importer' ), esc_html($taxonomy), esc_html($term['name']) );
632
  if ( defined('IMPORT_DEBUG') && IMPORT_DEBUG )
633
  echo ': ' . $t->get_error_message();
634
  echo '<br />';
 
635
  continue;
636
  }
637
  }
@@ -640,10 +662,16 @@ class WP_Import extends WP_Importer {
640
 
641
  foreach ( $terms_to_set as $tax => $ids ) {
642
  $tt_ids = wp_set_post_terms( $post_id, $ids, $tax );
 
643
  }
644
  unset( $post['terms'], $terms_to_set );
645
  }
646
 
 
 
 
 
 
647
  // add/update comments
648
  if ( ! empty( $post['comments'] ) ) {
649
  $num_comments = 0;
@@ -674,6 +702,7 @@ class WP_Import extends WP_Importer {
674
  $comment['comment_parent'] = $inserted_comments[$comment['comment_parent']];
675
  $comment = wp_filter_comment( $comment );
676
  $inserted_comments[$key] = wp_insert_comment( $comment );
 
677
 
678
  foreach( $comment['commentmeta'] as $meta ) {
679
  $value = maybe_unserialize( $meta['value'] );
@@ -686,10 +715,15 @@ class WP_Import extends WP_Importer {
686
  unset( $newcomments, $inserted_comments, $post['comments'] );
687
  }
688
 
 
 
 
 
 
689
  // add/update post meta
690
- if ( isset( $post['postmeta'] ) ) {
691
  foreach ( $post['postmeta'] as $meta ) {
692
- $key = apply_filters( 'import_post_meta_key', $meta['key'] );
693
  $value = false;
694
 
695
  if ( '_edit_last' == $key ) {
5
  Description: Import posts, pages, comments, custom fields, categories, tags and more from a WordPress export file.
6
  Author: wordpressdotorg
7
  Author URI: http://wordpress.org/
8
+ Version: 0.6.1
9
  Text Domain: wordpress-importer
10
  License: GPL version 2 or later - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
11
  */
393
  * Doesn't create a new category if its slug already exists
394
  */
395
  function process_categories() {
396
+ $this->categories = apply_filters( 'wp_import_categories', $this->categories );
397
+
398
  if ( empty( $this->categories ) )
399
  return;
400
 
439
  * Doesn't create a tag if its slug already exists
440
  */
441
  function process_tags() {
442
+ $this->tags = apply_filters( 'wp_import_tags', $this->tags );
443
+
444
  if ( empty( $this->tags ) )
445
  return;
446
 
479
  * Doesn't create a term its slug already exists
480
  */
481
  function process_terms() {
482
+ $this->terms = apply_filters( 'wp_import_terms', $this->terms );
483
+
484
  if ( empty( $this->terms ) )
485
  return;
486
 
528
  * Note that new/updated terms, comments and meta are imported for the last of the above.
529
  */
530
  function process_posts() {
531
+ $this->posts = apply_filters( 'wp_import_posts', $this->posts );
532
+
533
  foreach ( $this->posts as $post ) {
534
+ $post = apply_filters( 'wp_import_post_data_raw', $post );
535
+
536
  if ( ! post_type_exists( $post['post_type'] ) ) {
537
  printf( __( 'Failed to import &#8220;%s&#8221;: Invalid post type %s', 'wordpress-importer' ),
538
  esc_html($post['post_title']), esc_html($post['post_type']) );
539
  echo '<br />';
540
+ do_action( 'wp_import_post_exists', $post );
541
  continue;
542
  }
543
 
589
  'post_type' => $post['post_type'], 'post_password' => $post['post_password']
590
  );
591
 
592
+ $original_post_ID = $post['post_id'];
593
+ $postdata = apply_filters( 'wp_import_post_data_processed', $postdata, $post );
594
+
595
  if ( 'attachment' == $postdata['post_type'] ) {
596
  $remote_url = ! empty($post['attachment_url']) ? $post['attachment_url'] : $post['guid'];
597
 
611
  $comment_post_ID = $post_id = $this->process_attachment( $postdata, $remote_url );
612
  } else {
613
  $comment_post_ID = $post_id = wp_insert_post( $postdata, true );
614
+ do_action( 'wp_import_insert_post', $post_id, $original_post_ID, $postdata, $post );
615
  }
616
 
617
  if ( is_wp_error( $post_id ) ) {
630
  // map pre-import ID to local ID
631
  $this->processed_posts[intval($post['post_id'])] = (int) $post_id;
632
 
633
+ if ( ! isset( $post['terms'] ) )
634
+ $post['terms'] = array();
635
+
636
+ $post['terms'] = apply_filters( 'wp_import_post_terms', $post['terms'], $post_id, $post );
637
+
638
  // add categories, tags and other terms
639
  if ( ! empty( $post['terms'] ) ) {
640
  $terms_to_set = array();
647
  $t = wp_insert_term( $term['name'], $taxonomy, array( 'slug' => $term['slug'] ) );
648
  if ( ! is_wp_error( $t ) ) {
649
  $term_id = $t['term_id'];
650
+ do_action( 'wp_import_insert_term', $t, $term, $post_id, $post );
651
  } else {
652
  printf( __( 'Failed to import %s %s', 'wordpress-importer' ), esc_html($taxonomy), esc_html($term['name']) );
653
  if ( defined('IMPORT_DEBUG') && IMPORT_DEBUG )
654
  echo ': ' . $t->get_error_message();
655
  echo '<br />';
656
+ do_action( 'wp_import_insert_term_failed', $t, $term, $post_id, $post );
657
  continue;
658
  }
659
  }
662
 
663
  foreach ( $terms_to_set as $tax => $ids ) {
664
  $tt_ids = wp_set_post_terms( $post_id, $ids, $tax );
665
+ do_action( 'wp_import_set_post_terms', $tt_ids, $ids, $tax, $post_id, $post );
666
  }
667
  unset( $post['terms'], $terms_to_set );
668
  }
669
 
670
+ if ( ! isset( $post['comments'] ) )
671
+ $post['comments'] = array();
672
+
673
+ $post['comments'] = apply_filters( 'wp_import_post_comments', $post['comments'], $post_id, $post );
674
+
675
  // add/update comments
676
  if ( ! empty( $post['comments'] ) ) {
677
  $num_comments = 0;
702
  $comment['comment_parent'] = $inserted_comments[$comment['comment_parent']];
703
  $comment = wp_filter_comment( $comment );
704
  $inserted_comments[$key] = wp_insert_comment( $comment );
705
+ do_action( 'wp_import_insert_comment', $inserted_comments[$key], $comment, $comment_post_ID, $post );
706
 
707
  foreach( $comment['commentmeta'] as $meta ) {
708
  $value = maybe_unserialize( $meta['value'] );
715
  unset( $newcomments, $inserted_comments, $post['comments'] );
716
  }
717
 
718
+ if ( ! isset( $post['postmeta'] ) )
719
+ $post['postmeta'] = array();
720
+
721
+ $post['postmeta'] = apply_filters( 'wp_import_post_meta', $post['postmeta'], $post_id, $post );
722
+
723
  // add/update post meta
724
+ if ( ! empty( $post['postmeta'] ) ) {
725
  foreach ( $post['postmeta'] as $meta ) {
726
+ $key = apply_filters( 'import_post_meta_key', $meta['key'], $post_id, $post );
727
  $value = false;
728
 
729
  if ( '_edit_last' == $key ) {