Example #1
0
 public function display_cron_table_body()
 {
     $alternate = '';
     foreach ($this->crons as $timestamp => $cron_many) {
         foreach ($cron_many as $cron) {
             $alternate = $alternate == '' ? 'alternate' : '';
             echo '<tr class="single-cron cron-' . $cron['hash'] . ' ' . $alternate . '">';
             echo '<td class="column-hook">';
             echo $cron['hook'];
             $this->display_row_actions($cron['hook'], !isset($cron['cron']['interval']) ? 0 : $cron['cron']['interval'], $cron['cron']['args']);
             echo '</td>';
             echo '<td class="column-schedule">';
             echo empty($cron['cron']['schedule']) ? _e('single', 'acm') : $cron['cron']['schedule'];
             echo '</td>';
             echo '<td class="column-args">' . acm_get_cron_arguments($cron['cron']['args']) . '</td>';
             echo '<td class="column-next" data-timestamp="' . $timestamp . '">' . acm_get_next_cron_execution($timestamp) . '</td>';
             echo '<td class="column-action"><a class="execute-task button-secondary" data-task="' . $cron['hook'] . '" data-noonce="' . wp_create_nonce('execute_task_' . $cron['hook']) . '" data-args="' . implode(',', $cron['cron']['args']) . '">' . __('Execute', 'acm') . '</a></td>';
             echo '</tr>';
         }
     }
     // Add task row
     $this->add_task_row($alternate);
 }
Example #2
0
File: ajax.php Project: dannyoz/tls
 public function add_task()
 {
     $params = $_REQUEST;
     // Return error when noonce doesn't match
     if (!wp_verify_nonce($params['noonce'], 'add_task')) {
         die(json_encode(array('status' => 'error', 'details' => __('Sorry, wrong noonce.', 'acm'))));
     }
     // Hook empty
     if (empty($params['hook'])) {
         die(json_encode(array('status' => 'error', 'details' => __('Task hook can\'t be empty.', 'acm'))));
     }
     // Schedule name empty
     if (empty($params['schedule'])) {
         die(json_encode(array('status' => 'error', 'details' => __('Schedule name can\'t be empty.', 'acm'))));
     }
     // Prepare vars
     $hook = strtolower(trim(str_replace(' ', '_', $params['hook'])));
     $timestamp = time() + $params['offset'];
     $args = empty($params['args']) ? array() : explode(',', $params['args']);
     if ($params['schedule'] == 'single') {
         // schedule single event
         $status = wp_schedule_single_event($timestamp, $hook, $args);
         if ($status === false) {
             die(json_encode(array('status' => 'error', 'details' => __('Sorry, something goes wrong.', 'acm'))));
         }
     } else {
         // schedule regular event
         $status = wp_schedule_event($timestamp, $params['schedule'], $hook, $args);
         if ($status === false) {
             die(json_encode(array('status' => 'error', 'details' => __('Sorry, something goes wrong.', 'acm'))));
         }
     }
     // Render new table row
     $wptime_offset = get_option('gmt_offset') * 3600;
     $table = '<tr class="single-cron cron-added-new">';
     $table .= '<td class="column-hook">';
     $table .= $hook;
     $table .= '</td>';
     $table .= '<td class="column-schedule">';
     $table .= $params['schedule'];
     $table .= '</td>';
     $table .= '<td class="column-args">' . acm_get_cron_arguments($args) . '</td>';
     $table .= '<td class="column-next">' . acm_get_next_cron_execution($timestamp + $wptime_offset) . '</td>';
     $table .= '<td class="column-next"><a id="execute_task" data-task="' . $hook . '" data-noonce="' . wp_create_nonce('execute_task_' . $hook) . '" data-args="' . implode(',', $args) . '" class="button-secondary">' . __('Execute', 'acm') . '</a></td>';
     $table .= '</tr>';
     die(json_encode(array('status' => 'success', 'table' => $table, 'timestamp' => $timestamp)));
 }