/** * Delete a job. * @synopsis <id> [--confirm] * * @param $args * @param $assoc * * @return bool */ public function delete($args, $assoc) { list($id) = $args; if (isset($assoc['confirm'])) { $job = \MyWPBackup\Admin\Job::get($id); if (!$job) { echo sprintf(__('No such job with ID %s.', 'my-wp-backup'), $id) . "\n"; return false; } \MyWPBackup\Admin\Job::delete($id); echo sprintf(__('Deleted job %s.', 'my-wp-backup'), $job['job_name']) . "\n"; } else { echo 'Please add --confirm to really delete the job.' . "\n"; } return true; }
public function post_run_job() { if (!isset($_POST['_wpnonce']) || !isset($_POST['id'])) { return; } $nonce = filter_input(INPUT_POST, '_wpnonce', FILTER_SANITIZE_STRING); if (!wp_verify_nonce($nonce, 'my-wp-backup-run-job')) { wp_die(esc_html__('Nope! Security check failed!', 'my-wp-backup')); } $id = absint($_POST['id']); //input var okay $job = Job::get($id); if (!$job) { wp_die(esc_html__('Nope! Security check failed!', 'my-wp-backup')); } if (false !== ($running_job = get_transient('my-wp-backup-running'))) { if ($id !== $running_job['id']) { add_settings_error('', '', sprintf(__('Job "%s" is currently running.', 'my-wp-backup'), $running_job['job_name'])); set_transient('settings_errors', get_settings_errors()); wp_safe_redirect($this->admin->get_page_url('jobs', array('settings-updated' => 1))); } } if ('manual' === $job['schedule_type']) { $uniqid = uniqid(); wp_schedule_single_event(time(), 'wp_backup_run_job', array(array($id, $uniqid))); wp_safe_redirect($this->admin->get_page_url('jobs', array('action' => 'view', 'uniqid' => $uniqid, 'id' => $id))); } else { add_settings_error('', '', sprintf(__('Cannot manually run job of schedule type "%s".', 'my-wp-backup'), $job['schedule_type'])); set_transient('settings_errors', get_settings_errors()); wp_safe_redirect($this->admin->get_page_url('jobs', array('settings-updated' => 1))); } }
<input type="hidden" name="my-wp-backup-jobs[id]" value="<?php echo esc_attr($id); ?> "> <input type="hidden" name="my-wp-backup-jobs[action]" value="<?php echo esc_attr($action); ?> "> <input type="hidden" name="tour" value="<?php echo esc_attr(isset($_GET['tour']) && 'yes' === $_GET['tour'] ? 'yes' : 'no'); ?> "> <?php if ('edit' === $action) { $job = Job::get($id); } else { $job = Job::$form_defaults; } ?> <div id="section-general" class="nav-tab-content nav-tab-content-active"> <table class="form-table"> <tbody> <tr> <th scope="row"> <label for="job-name"><?php esc_html_e('Job Name', 'my-wp-backup'); ?> </label> </th>