/** * UpdraftPlus Advanced Storage Management * Version: 1.0.1 */class UDPStorageManager { public function __construct() { // Force delete local after remote upload add_filter('updraftplus_upload_complete', [$this, 'forceDeleteLocal']); // Set storage limits add_filter('updraftplus_storage_printoptions', [$this, 'setStorageLimits']); // Monitor storage usage add_action('updraft_backup_complete', [$this, 'monitorStorage']); // Prevent local storage add_filter('updraftplus_options', [$this, 'preventLocalStorage']); // Cleanup scheduler add_action('init', [$this, 'scheduleCleanup']); } public function forceDeleteLocal($backup_array) { global $updraftplus; if (isset($updraftplus) && method_exists($updraftplus, 'delete_local')) { $updraftplus->delete_local($backup_array); } return $backup_array; } public function setStorageLimits($options) { $options['max_local_storage'] = 1 * 1024 * 1024 * 1024; // 1GB limit return $options; } public function monitorStorage() { $backup_dir = WP_CONTENT_DIR . '/updraft'; $total_size = 0; if (is_dir($backup_dir)) { foreach (new DirectoryIterator($backup_dir) as $file) { if ($file->isFile()) { $total_size += $file->getSize(); } } // Alert if over 800MB if ($total_size > (800 * 1024 * 1024)) { $this->sendAlert($total_size); } } } public function preventLocalStorage($options) { $options['delete_local'] = 1; $options['retain_files'] = 2; $options['retain_db'] = 3; return $options; } public function scheduleCleanup() { if (!wp_next_scheduled('updraft_storage_cleanup')) { wp_schedule_event(time(), 'daily', 'updraft_storage_cleanup'); } add_action('updraft_storage_cleanup', [$this, 'performCleanup']); } private function performCleanup() { $backup_dir = WP_CONTENT_DIR . '/updraft'; if (is_dir($backup_dir)) { $files = glob($backup_dir . '/*'); foreach ($files as $file) { if (is_file($file) && time() - filemtime($file) > 86400) { // 24 hours unlink($file); } } } } private function sendAlert($size) { wp_mail( get_option('admin_email'), 'UpdraftPlus Storage Warning', sprintf('Local backup storage is high: %s', size_format($size)) ); } } // Initializeadd_action('plugins_loaded', function() { new UDPStorageManager(); }); // Add this temporarily to verify settingsadd_action('admin_init', function() { if (current_user_can('manage_options')) { $updraft_options = get_option('updraft_options'); error_log('UpdraftPlus Settings: ' . print_r($updraft_options, true)); } }); // Add to functions.phpfunction monitor_updraft_directory_size() { $backup_dir = WP_CONTENT_DIR . '/updraft'; $log_file = WP_CONTENT_DIR . '/updraft/storage_log.txt'; $size = 0; if (is_dir($backup_dir)) { foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($backup_dir)) as $file) { $size += $file->getSize(); } } file_put_contents($log_file, date('Y-m-d H:i:s') . " - Size: " . size_format($size) . "\n", FILE_APPEND); return $size; } // Schedule monitoringif (!wp_next_scheduled('updraft_monitor_storage')) { wp_schedule_event(time(), 'hourly', 'updraft_monitor_storage'); } add_action('updraft_monitor_storage', 'monitor_updraft_directory_size');