[IMPORTANT] Movabletype Importer Patch for WordPress 2.0
-
First of all, I’m very sorry for not doing this completely right. Trac didn’t let me in at all, FreeNode is down so I can’t ask you guys what to do. I decided to post this patch anyway.
There are a few problems with the current MT importer in WordPress 2.0:
– Comments are inserted to database but without a comment_approved status. This causes WP to ignore them.– Pings permissions aren’t inserted correctly. Pings are *always allowed. (Wrong variable name $post_allow_pings)
– A new author is created with “subscriber” permissions on each import. (Tiny bug related to using $this->newauthornames[$j] instead of $this->newauthornames[$this->j]
– <!–more–> tag is *always* because wp_kses_split2 says is “seriously malformed” ?? I added a low-priority filter as a workaround.
I guess that’s it. Here’s the patch if you’re interested:
Index: mt.php
===================================================================
--- mt.php (revision 3378)
+++ mt.php (working copy)
@@ -54,7 +54,7 @@
if (!(in_array($author, $this->mtnames))) { //a new mt author name is found
++ $this->j;
$this->mtnames[$this->j] = $author; //add that new mt author name to an array
- $user_id = username_exists($this->newauthornames[$j]); //check if the new author name defined by the user is a pre-existing wp user
+ $user_id = username_exists($this->newauthornames[$this->j]); //check if the new author name defined by the user is a pre-existing wp user
if (!$user_id) { //banging my head against the desk now.
if ($newauthornames[$this->j] == 'left_blank') { //check if the user does not want to change the authorname
$user_id = wp_create_user($author, $pass);
@@ -200,7 +200,7 @@
preg_match("|-----nEXTENDED BODY:(.*)|s", $post, $extended);
$extended = trim($extended[1]);
if ('' != $extended)
- $extended = "n<!--more-->n$extended";
+ $extended = "n%%%%more%%%%n$extended";
$post = preg_replace("|(-----nEXTENDED BODY:.*)|s", '', $post);// Now for the main body
@@ -243,11 +243,11 @@
$post_convert_breaks = $value;
break;
case 'ALLOW PINGS' :
- $post_allow_pings = trim($meta[2][0]);
- if ($post_allow_pings == 1) {
- $post_allow_pings = 'open';
+ $ping_status = trim($meta[2][0]);
+ if ($ping_status == 1) {
+ $ping_status = 'open';
} else {
- $post_allow_pings = 'closed';
+ $ping_status = 'closed';
}
break;
case 'PRIMARY CATEGORY' :
@@ -319,9 +319,12 @@$comment_content = $wpdb->escape(trim($comment));
$comment_content = str_replace('-----', '', $comment_content);
+
+ $comment_approved = 1;
+
// Check if it's already there
if (!comment_exists($comment_author, $comment_date)) {
- $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_url', 'comment_author_email', 'comment_author_IP', 'comment_date', 'comment_content');
+ $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_url', 'comment_author_email', 'comment_author_IP', 'comment_date', 'comment_content', 'comment_approved');
$commentdata = wp_filter_comment($commentdata);
wp_insert_comment($commentdata);
$num_comments++;
@@ -366,10 +369,12 @@
$comment_content = "<strong>$ping_title</strong>nn$comment_content";$comment_type = 'trackback';
-
+
+ $comment_approved = 1;
+
// Check if it's already there
if (!comment_exists($comment_author, $comment_date)) {
- $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_url', 'comment_author_email', 'comment_author_IP', 'comment_date', 'comment_content', 'comment_type');
+ $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_url', 'comment_author_email', 'comment_author_IP', 'comment_date', 'comment_content', 'comment_type', 'comment_approved');
$commentdata = wp_filter_comment($commentdata);
wp_insert_comment($commentdata);
$num_pings++;
@@ -423,6 +428,12 @@
}
}+// Kses removes <!--more-->. Here's a nasty workaround :)
+function mt_import_more_filter($data) {
+ return str_replace('%%%%more%%%%', '<!--more-->', $data);
+}
+add_filter('content_save_pre', 'mt_import_more_filter', 100);
+
$mt_import = new MT_Import();register_importer('mt', 'Movable Type', __('Import posts and comments from your Movable Type blog'), array ($mt_import, 'dispatch'));
- The topic ‘[IMPORTANT] Movabletype Importer Patch for WordPress 2.0’ is closed to new replies.