Skip to content

Instantly share code, notes, and snippets.

@greg-randall
Created January 31, 2024 14:02
Show Gist options
  • Save greg-randall/64490892ae44ec632041082ad6ea5176 to your computer and use it in GitHub Desktop.
Save greg-randall/64490892ae44ec632041082ad6ea5176 to your computer and use it in GitHub Desktop.
WordPress shortcode to export a site, useful if your site is super locked down.
function export_all_posts() {
// Ensure the export function is available
if (!function_exists('export_wp')) {
require_once ABSPATH . 'wp-admin/includes/export.php';
}
// Start output buffering
ob_start();
// Call the export function
export_wp();
// Get the output
$output = ob_get_clean();
$filename = "export_" . sanitize_title( get_bloginfo('name') ) . "_" . time() . ".xml";
// Save the output to a file
file_put_contents(ABSPATH . "wp-content/uploads/$filename", $output);
}
add_shortcode('export_all_posts', 'export_all_posts');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment