/** * @param string $type the type of the schedule * @param array $times { * An array of time arguments. Optional. * * @type int $minutes The minute to start the schedule on. Defaults to current time + 10 minutes. Accepts * any valid `date( 'i' )` output. * @type int $hours The hour to start the schedule on. Defaults to current time + 10 minutes. Accepts * any valid `date( 'G' )` output. * @type string $day_of_week The day of the week to start the schedule on. Defaults to current time + 10 minutes. Accepts * any valid `date( 'l' )` output. * @type int $day_of_month The day of the month to start the schedule on. Defaults to current time + 10 minutes. Accepts * any valid `date( 'j' )` output. * @type int $now The current time. Defaults to `time()`. Accepts any valid timestamp. * * } * @return int $timestamp Returns the resulting timestamp on success and Int 0 on failure */ function determine_start_time($type, $times = array()) { // Default to in 10 minutes if (!empty($times['now'])) { $default_timestamp = $times['now'] + 600; } else { $default_timestamp = time() + 600; } $default_times = array('minutes' => date('i', $default_timestamp), 'hours' => date('G', $default_timestamp), 'day_of_week' => date('l', $default_timestamp), 'day_of_month' => date('j', $default_timestamp), 'now' => time()); $args = wp_parse_args($times, $default_times); $intervals = get_cron_schedules(); // Allow the hours and minutes to be overwritten by a constant if (defined('HMBKP_SCHEDULE_TIME') && HMBKP_SCHEDULE_TIME) { $hm = HMBKP_SCHEDULE_TIME; } else { // The hour and minute that the schedule should start on $hm = $args['hours'] . ':' . $args['minutes'] . ':00'; } switch ($type) { case 'hourly': case 'daily': case 'twicedaily': // The next occurance of the specified time $schedule_start = $hm; break; case 'weekly': case 'fortnightly': // The next day of the week at the specified time $schedule_start = $args['day_of_week'] . ' ' . $hm; break; case 'monthly': // The occurance of the time on the specified day of the month $schedule_start = date('F', $args['now']) . ' ' . $args['day_of_month'] . ' ' . $hm; // If we've already gone past that day this month then we'll need to start next month if (strtotime($schedule_start, $args['now']) <= $args['now']) { $schedule_start = date('F', strtotime('+ 1 month', $args['now'])) . ' ' . $args['day_of_month'] . ' ' . $hm; } // If that's still in the past then we'll need to jump to next year if (strtotime($schedule_start, $args['now']) <= $args['now']) { $schedule_start = date('F', strtotime('+ 1 month', $args['now'])) . ' ' . $args['day_of_month'] . ' ' . date('Y', strtotime('+ 1 year', $args['now'])) . ' ' . $hm; } break; default: return 0; } $timestamp = strtotime($schedule_start, $args['now']); // Convert to UTC $timestamp -= get_option('gmt_offset') * 3600; // If the scheduled time already passed then keep adding the interval until we get to a future date while ($timestamp <= $args['now']) { $timestamp += $intervals[$type]['interval']; } return $timestamp; }
_e('Schedule', 'backupwordpress'); ?> </label> </th> <td> <select name="hmbkp_schedule_recurrence[hmbkp_type]" id="hmbkp_schedule_recurrence_type"> <option value="manually"><?php _e('Manual Only', 'backupwordpress'); ?> </option> <?php foreach (get_cron_schedules() as $cron_schedule => $cron_details) { ?> <option <?php selected($schedule->get_reoccurrence(), $cron_schedule); ?> value="<?php echo esc_attr($cron_schedule); ?> "> <?php esc_html_e($cron_details['display'], 'backupwordpress'); ?> </option>
/** * Setup the schedule * */ public function setUp() { $this->schedule = new Scheduled_Backup('unit-test'); $this->recurrences = get_cron_schedules(); }