$error = true; } $schedule['remote_destinations'] = $submitted_schedule['data']['remote_destinations']; $schedule['delete_after'] = $submitted_schedule['data']['delete_after']; if ($error === false) { $next_index = pb_backupbuddy::$options['next_schedule_index']; // v2.1.3: $next_index = end( array_keys( pb_backupbuddy::$options['schedules'] ) ) + 1; pb_backupbuddy::$options['next_schedule_index']++; // This change will be saved in savesettings function below. pb_backupbuddy::$options['schedules'][$next_index] = $schedule; $result = wp_schedule_event($schedule['first_run'], $schedule['interval'], 'pb_backupbuddy-cron_scheduled_backup', array($next_index)); if ($result === false) { pb_backupbuddy::alert('Error scheduling event with WordPress. Your schedule may not work properly. Please try again. Error #3488439.', true); } pb_backupbuddy::save(); $schedule_form->clear_values(); pb_backupbuddy::alert('Added new schedule `' . htmlentities($schedule['title']) . '`.'); } } else { // EDIT SCHEDULE. Forma handles saving; just need to update timestamp. $first_run = pb_backupbuddy::$format->unlocalize_time(strtotime($submitted_schedule['data']['first_run'])); if ($first_run == 0 || $first_run == 18000) { pb_backupbuddy::alert(sprintf(__('Invalid time format. Please use the specified format / example %s', 'it-l10n-backupbuddy'), $date_format_example)); $error = true; } pb_backupbuddy::$options['schedules'][pb_backupbuddy::_GET('edit')]['first_run'] = $first_run; $next_scheduled_time = wp_next_scheduled('pb_backupbuddy-cron_scheduled_backup', array((int) $_GET['edit'])); wp_unschedule_event($next_scheduled_time, 'pb_backupbuddy-cron_scheduled_backup', array((int) $_GET['edit'])); // Remove old schedule. pb_backupbuddy::$options['schedules'][$_GET['edit']]['first_run'] $result = wp_schedule_event($first_run, $submitted_schedule['data']['interval'], 'pb_backupbuddy-cron_scheduled_backup', array((int) $_GET['edit'])); // Add new schedule.