Last active
October 2, 2023 07:02
-
-
Save thehelvetian/e39de6832824fbf569f848a4f5e42ea6 to your computer and use it in GitHub Desktop.
WP Export
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* [$outPath description] | |
* @var string | |
*/ | |
$outPath = 'xml/'; | |
/** | |
* [$fileName description] | |
* @var string | |
*/ | |
$fileName = 'wp_images_' . date('m-d-Y-His A e') . '.xml'; | |
/** | |
* Include the WordPress bootstrap | |
*/ | |
require(dirname(__FILE__) . '/wp-load.php'); | |
/** | |
* ABSPATH is not defined until wp-load.php has been included | |
*/ | |
defined('ABSPATH') or die ("test!"); | |
/** | |
* Include WP's export classes/methods | |
*/ | |
require_once(ABSPATH.'/wp-admin/includes/export.php'); | |
/** | |
* Start the output buffer | |
*/ | |
ob_start(); | |
/** | |
* Write the export into the buffer | |
*/ | |
export_wp('attachment'); | |
/** | |
* Get the export data from the buffer & clean up | |
*/ | |
$xml = ob_get_clean(); | |
/** | |
* Make sure the $outPath exists | |
*/ | |
if( !file_exists($outPath) ) { | |
mkdir(dirname(__FILE__).'/'.$outPath, 0755); | |
} | |
/** | |
* Write out the export data into a file | |
*/ | |
file_put_contents($outPath . $fileName, $xml); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment