Wednesday, November 25, 2009

WordPress CLI Export

Why would you want to use the command line to export your WordPress blog? Well, if you are like me and manage 300+ blogs, you'll want an easy way to export a blog without logging into each and every WordPress admin page to click around and export that xml file.

Anyhow, if you poke around in the wp-admin/export.php page, you'll notice that it calls a function export_wp (which is defined at wp-admin/includes/export.php). And voila! Amazingly that's all you need!

It'll spit out the xml to stdout so you'll want to grab that buffer! See the code below to generally see how I did things.

Simple. Very useful! Cheers!


include 'wp-config.php';
include 'wp-admin/includes/export.php';

ob_start();
export_wp();
$file = ob_get_contents();
ob_end_clean();

$fh = fopen("wordpress-" . date('Y-m-d') . ".xml", 'w');
fwrite($fh, $file);
fclose($fh);

1 comment:

Unknown said...
This comment has been removed by the author.