Skip to content

Instantly share code, notes, and snippets.

@trueqap
Created November 24, 2025 08:16
Show Gist options
  • Select an option

  • Save trueqap/1d44eab5c7f98eec2dd4e9096095df6a to your computer and use it in GitHub Desktop.

Select an option

Save trueqap/1d44eab5c7f98eec2dd4e9096095df6a to your computer and use it in GitHub Desktop.
Auto-cleanup .wpress backup files from All-in-One WP Migration storage
<?php
/**
* Auto-cleanup .wpress backup files from All-in-One WP Migration storage
*
* Automatically deletes .wpress files from the All-in-One WP Migration
* storage folder once daily to prevent disk space issues.
*
* Usage: Add this snippet to your theme's functions.php or use a
* code snippets plugin.
*
* @author trueqap
* @version 1.0.0
*/
// Schedule daily cleanup event
add_action('init', function() {
if (!wp_next_scheduled('cleanup_wpress_files')) {
wp_schedule_event(time(), 'daily', 'cleanup_wpress_files');
}
});
// Cleanup function
add_action('cleanup_wpress_files', function() {
$dir = WP_CONTENT_DIR . '/plugins/all-in-one-wp-migration/storage';
if (!is_dir($dir)) {
return;
}
foreach (glob("$dir/*.wpress") as $file) {
if (is_file($file)) {
unlink($file);
}
}
});
// Optional: Remove scheduled event on theme/plugin deactivation
// Uncomment if needed:
// register_deactivation_hook(__FILE__, function() {
// wp_clear_scheduled_hook('cleanup_wpress_files');
// });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment