Make WordPress Core

Opened 16 years ago

Closed 16 years ago

Last modified 16 years ago

#8474 closed defect (bug) (fixed)

wordpress.com xml import fatal error

Reported by: jaredh123's profile 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 16 years ago.
export file that won't import

Download all attachments as: .zip

Change History (4)

@jaredh123
16 years ago

export file that won't import

#1 @jaredh123
16 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

#2 @ryan
16 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

#3 @ryan
16 years ago

Try that out.

Note: See TracTickets for help on using tickets.