Extending WordPress migration classes

The builtin wordpress_migrate classes can be extended for custom situations, such as mapping incoming postmeta data to node fields. The basic approach:

1. Extend the appropriate class, such as the WordPressBlogEntry class with your custom behavior - add field mappings in __construct(), manipulate the body ($row->content) in prepareRow(), etc.
2. Extend the WordPressBlog class, and override migrationClasses to point to your custom classes:

class MyCustomBlog extends WordPressBlog {
  public function migrationClasses() {
    $classes = parent::migrationClasses();
    $classes['WordPressBlogEntry'] = 'MyCustomBlogEntry';
    $classes['WordPressPage'] = 'MyCustomPage';
    return $classes;
  }
}

3. Set the wordpress_migrate_blog_class variable to point at your WordPressBlog class. For example, add this to settings.php:

$conf['wordpress_migrate_blog_class'] = 'MyCustomBlog';

Comments

davemurphy’s picture

How do you configure WordPress Migrate to spawn a drush command to perform the import from within the devel module??

rgds Dave

mikeryan’s picture

@Dave: The devel module has a variable editor at http://www.example.com/devel/variable, where I was imagining you could add the variables described above. However, it looks like it only supports editing and deleting variables, not adding them, so it won't help you. I'll remove that reference from the docs.

Note that there are no notifications of comments on documentation, it's pure happenstance that I saw this just a few days after you posted it (and it'll be happenstance if you see this reply) - the issue queue is a much better place to post questions about a module than on the documentation pages.

hanoii’s picture

Where is the best place to put these classes?

acctman’s picture

have you figured out where the classes are placed?

hanoii’s picture

I placed it in a custom module and it worked.

efpapado’s picture

Can you describe with a few more details? I can't make it work by following those instructions. The default class is still used.

hanoii’s picture

This was a while, but I just checked and I put it in the actual .module file.

I just noticed that I have an include file in the module info that's really not there, so I must have tried that first and then probably needed to put it on the .module file to work, although I am back guessing here.

Hope this helps.