Daily Archives: 2012-06-30

How to export a data file from a WordPress plugin

As part of my hacking on WordPrss, I got to a point where I wanted to let folks import and export OPML files.
Exporting a file from a WordPress plugin doesn’t seem to be very well documented. I found an older article about it – here’s my take.

Provide a link to the file export

Export the data

This file isn’t getting included in through the normal wordpress mechanisms, so it has to do some more work than the rest of your plugin does. If you want to use the $wpdb or other handy wordpress items, you have to include those in.
I was about to hack up a way to include wp-config.php or wp-load.php when I ran across the simply named Don’t Include WP-Load, Please. He recommends a clever way to handle it all within wordpress, which I quite like. See below.

Now you can build out your export file – in this case export_opml.php – knowing that all of the WordPress utilities are there for you to use.