/** * Catch the edit schedule form * * Validate and either return errors or update the schedule */ function hmnkp_edit_schedule_submit() { if (empty($_GET['hmbkp_schedule_id'])) { die; } $schedule = new HMBKP_Scheduled_Backup(sanitize_text_field($_GET['hmbkp_schedule_id'])); $errors = array(); if (isset($_GET['hmbkp_schedule_type'])) { $schedule_type = sanitize_text_field($_GET['hmbkp_schedule_type']); if (!trim($schedule_type)) { $errors['hmbkp_schedule_type'] = __('Backup type cannot be empty', 'hmbkp'); } elseif (!in_array($schedule_type, array('complete', 'file', 'database'))) { $errors['hmbkp_schedule_type'] = __('Invalid backup type', 'hmbkp'); } else { $schedule->set_type($schedule_type); } } if (isset($_GET['hmbkp_schedule_reoccurrence'])) { $schedule_reoccurrence = sanitize_text_field($_GET['hmbkp_schedule_reoccurrence']); if (empty($schedule_reoccurrence)) { $errors['hmbkp_schedule_reoccurrence'] = __('Schedule cannot be empty', 'hmbkp'); } elseif (!in_array($schedule_reoccurrence, array_keys($schedule->get_cron_schedules())) && $schedule_reoccurrence !== 'manually') { $errors['hmbkp_schedule_reoccurrence'] = __('Invalid schedule', 'hmbkp'); } else { $schedule->set_reoccurrence($schedule_reoccurrence); } } if (isset($_GET['hmbkp_schedule_max_backups'])) { $schedule_max_backups = sanitize_text_field($_GET['hmbkp_schedule_max_backups']); if (empty($schedule_max_backups)) { $errors['hmbkp_schedule_max_backups'] = __('Max backups can\'t be empty', 'hmbkp'); } elseif (!is_numeric($schedule_max_backups)) { $errors['hmbkp_schedule_max_backups'] = __('Max backups must be a number', 'hmbkp'); } elseif (!($schedule_max_backups >= 1)) { $errors['hmbkp_schedule_max_backups'] = __('Max backups must be greater than 0', 'hmbkp'); } else { $schedule->set_max_backups((int) $schedule_max_backups); } // Remove any old backups in-case max backups was reduced $schedule->delete_old_backups(); } // Save the service options foreach (HMBKP_Services::get_services($schedule) as $service) { $errors = array_merge($errors, $service->save()); } $schedule->save(); if ($errors) { echo json_encode($errors); } die; }
/** * Setup the default backup schedules */ function hmbkp_setup_default_schedules() { $schedules = HMBKP_Schedules::get_instance(); if ($schedules->get_schedules()) { return; } /** * Schedule a database backup daily and store backups * for the last 2 weeks */ $database_daily = new HMBKP_Scheduled_Backup('default-1'); $database_daily->set_type('database'); $database_daily->set_reoccurrence('hmbkp_daily'); $database_daily->set_max_backups(14); $database_daily->save(); /** * Schedule a complete backup to run weekly and store backups for * the last 3 months */ $complete_weekly = new HMBKP_Scheduled_Backup('default-2'); $complete_weekly->set_type('complete'); $complete_weekly->set_reoccurrence('hmbkp_weekly'); $complete_weekly->set_max_backups(12); $complete_weekly->save(); function hmbkp_default_schedules_setup_warning() { echo '<div id="hmbkp-warning" class="updated fade"><p><strong>' . __('BackUpWordPress has setup your default schedules.', 'hmbkp') . '</strong> ' . __('By default BackUpWordPress performs a daily backup of your database and a weekly backup of your database & files. You can modify these schedules.', 'hmbkp') . '</p></div>'; } add_action('admin_notices', 'hmbkp_default_schedules_setup_warning'); }
/** * Setup the default backup schedules */ function hmbkp_setup_default_schedules() { $schedules = HMBKP_Schedules::get_instance(); if ($schedules->get_schedules()) { return; } /** * Schedule a database backup daily and store backups * for the last 2 weeks */ $database_daily = new HMBKP_Scheduled_Backup((string) time()); $database_daily->set_type('database'); $database_daily->set_schedule_start_time(hmbkp_determine_start_time('hmbkp_daily', array('hours' => '23', 'minutes' => '0'))); $database_daily->set_reoccurrence('hmbkp_daily'); $database_daily->set_max_backups(7); $database_daily->save(); /** * Schedule a complete backup to run weekly and store backups for * the last 3 months */ $complete_weekly = new HMBKP_Scheduled_Backup((string) (time() + 1)); $complete_weekly->set_type('complete'); $complete_weekly->set_schedule_start_time(hmbkp_determine_start_time('hmbkp_weekly', array('day_of_week' => 'sunday', 'hours' => '3', 'minutes' => '0'))); $complete_weekly->set_reoccurrence('hmbkp_weekly'); $complete_weekly->set_max_backups(3); $complete_weekly->save(); $schedules->refresh_schedules(); function hmbkp_default_schedules_setup_warning() { echo '<div id="hmbkp-warning" class="updated fade"><p><strong>' . __('BackUpWordPress has setup your default schedules.', 'hmbkp') . '</strong> ' . __('By default BackUpWordPress performs a daily backup of your database and a weekly backup of your database & files. You can modify these schedules.', 'hmbkp') . '</p></div>'; } add_action('admin_notices', 'hmbkp_default_schedules_setup_warning'); }