WordPress.org

Make WordPress Core

Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#8474 closed defect (bug) (fixed)

wordpress.com xml import fatal error

Reported by: jaredh123 Owned by:
Milestone: 2.7 Priority: normal
Severity: normal Version: 2.6.1
Component: Import Keywords:
Focuses: Cc:

Description

self-hosted WP 2.6.5 is choking on a xml export file from wordpress.com, giving this error:

Fatal error: Cannot use object of type WP_Error as array in /home/moorep/public_html/blog/wp-admin/import/wordpress.php on line 465

which is this:
$tag_id = $tag_idterm_id?;

Seems to be related to empty CDATA tags like <![CDATA[]]>

lots of people having issues:
http://tinyurl.com/667aes
http://tinyurl.com/6af98n

attached is an export file if that helps

Attachments (1)

import.xml.zip (119.3 KB) - added by jaredh123 7 years ago.
export file that won't import

Download all attachments as: .zip

Change History (4)

@jaredh1237 years ago

export file that won't import

comment:1 @jaredh1237 years ago

This is horrible probably (because I don't understand the WP_error object, and am a beginner with PHP, but what worked for me to fix it was change this: (wp-admin/import/wordpress.php lines 453 - 470)

// Add tags.
if (count($tags) > 0) {
	$post_tags = array();
	foreach ($tags as $tag) {
		$slug = sanitize_term_field('slug', $tag, 0, 'post_tag', 'db');
		$tag_obj = get_term_by('slug', $slug, 'post_tag');
		$tag_id = 0;
		if ( ! empty($tag_obj) )
			$tag_id = $tag_obj->term_id;
		if ( $tag_id == 0 ) {
			$tag = $wpdb->escape($tag);
			$tag_id = wp_insert_term($tag, 'post_tag');
			$tag_id = $tag_id['term_id'];
		}
		$post_tags[] = intval($tag_id);
	}
	wp_set_post_tags($post_id, $post_tags);
}

with this:

// Add tags.
if (count($tags) > 0) {
	$error = false;
	$post_tags = array();
	foreach ($tags as $tag) {
		$slug = sanitize_term_field('slug', $tag, 0, 'post_tag', 'db');
		$tag_obj = get_term_by('slug', $slug, 'post_tag');
		$tag_id = 0;
		if ( ! empty($tag_obj) )
			$tag_id = $tag_obj->term_id;
		if ( $tag_id == 0 ) {
			$tag = $wpdb->escape($tag);
			$tag_id = wp_insert_term($tag, 'post_tag');
			if ( is_object( $tag_id ) ) {
				$error = true;
			} else {
				$tag_id = $tag_id['term_id'];
			}
		}
		if ( ! $error ) $post_tags[] = intval($tag_id);
	}
	if ( ! $error ) wp_set_post_tags($post_id, $post_tags);
}

which is just a rudimentary check for an object to break out of the if...

sorry, i don't know how to create a true diff

comment:2 @ryan7 years ago

  • Resolution set to fixed
  • Status changed from new to closed

(In [10021]) Don't import cat and tags with empty string for name. Check for WP_Error after term insertion. fixes #8474

comment:3 @ryan7 years ago

Try that out.

Note: See TracTickets for help on using tickets.