4
August 23, 2013

How to fix WordPress to Tumblr video importing

Videos on Tumblr come in all shapes and sizes. Youtube & Metacafe videos are done in iframes, directly uploaded ones in  html5, and then there are all the Javascript players in between. If you’re having issues with the videos importing, it most likely is because of the way WordPress sanitizes the Tumblr posts.

WordPress removes iframes from posts

That’s the main issue. Luckily, there is a solution to disable the WordPress filters while you’re importing.

Below line 411 in tumblr-importer.php, add this line:

kses_remove_filters();

Making your code look like:

do_action( 'tumblr_importing_post', $post );
kses_remove_filters();
$id = wp_insert_post( $post );

And then down on line 434 add this:

kses_init_filters();

Making your code look like:

$this->save_vars();
kses_init_filters();
} while ( false != ($post = next($imported_posts) ) && $this->have_time() );

The kses filters are in place to help prevent malicious code from being imported, and the code above simply disabled them before the import, and then reenabled them once it was completed. Since we probably trust YouTube and the other video sources, we’re allowing the iframes to live inside posts.

You’ll have to do the same modifications if you’re importing drafts. Just add the code to lines 482 and 494 respectively. You can download the importer with my modifications here (make sure you remove the .txt extension).

  • http://HQMedEd.com/ Scott Joing

    Brian – thanks for this post. It didn’t work for me though. Still no videos making it over to wordpress from tumblr.

    • http://brianshaffer.com/ Brian Shaffer

      Scott – There are hundreds of reasons this might be. Try to isolate the problem as much as possible. Do directly uploaded ones work? What about YouTube videos posted to Tumblr? Is it just the video files that aren’t making it, or do audio posts fail as well? Does the post text make it, but the video itself is blank? If you can answer some of these questions, it should help you pinpoint the issue.

      After you’ve done that, you can go in the importer script and log the output. That’s how I discovered this fix – because the body of the post from Tumblr was grabbed correctly, but it was in the saving to the WordPress database that had the error.

  • http://HQMedEd.com/ Scott Joing

    Brian – I ended up importing from tumblr to a temporary wordpress.com blog, then exporting as wordpress, then importing to my self-hosted wordpress blog and everything worked great. Turns out the tumblr importing process via a wordpress.com blog is different than the process on a self-hosted (non-wordpress.com) wordpress install. The plugins must be different.

    • http://brianshaffer.com/ Brian Shaffer

      Good to know. Thanks Scott – hopefully this will help someone else too!