Created
January 31, 2024 14:02
-
-
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.
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
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