/** * Update Orbis task meta data * * @param array $data */ function update_orbis_task_meta($post_id, array $data = null) { if (is_array($data)) { // Due At if (isset($data['_orbis_task_due_at_string'])) { $date_string = $data['_orbis_task_due_at_string']; $timestamp = strtotime($date_string); if ($timestamp !== false) { $date = date('Y-m-d H:i:s', $timestamp); $date_gmt = get_gmt_from_date($date); $data['_orbis_task_due_at'] = $date; $data['_orbis_task_due_at_gmt'] = $date_gmt; } } // Seconds if (isset($data['_orbis_task_seconds_string'])) { $data['_orbis_task_seconds'] = orbis_parse_time($data['_orbis_task_seconds_string']); } // Meta foreach ($data as $key => $value) { if ($value === '' || $value === null) { delete_post_meta($post_id, $key); } else { update_post_meta($post_id, $key, $value); } } // Sync orbis_save_task_sync($post_id); } }
function orbis_tasks_maybe_finish_task() { if (filter_has_var(INPUT_GET, 'task') && filter_has_var(INPUT_GET, 'action')) { $post_id = filter_input(INPUT_GET, 'task', FILTER_SANITIZE_NUMBER_INT); $action = filter_input(INPUT_GET, 'action', FILTER_SANITIZE_STRING); $nonce = filter_input(INPUT_GET, '_wpnonce', FILTER_SANITIZE_STRING); $nonce_action = 'finish-task_' . $post_id; if (wp_verify_nonce($nonce, $nonce_action)) { global $wpdb; update_post_meta($post_id, '_orbis_task_completed', true); orbis_save_task_sync($post_id, get_post($post_id)); $url = add_query_arg(array('task' => false, 'action' => false, '_wpnonce' => false)); wp_redirect($url); exit; } else { exit('Nonce is invalid'); } } }
public function set_task_due_at() { $object = json_decode(file_get_contents('php://input'), false); if ($object) { $post_id = $object->post_id; $task = new Orbis_Task($object->post_id); $task->set_due_at($object->due_at); orbis_save_task_sync($post_id); $task = $this->get_task($post_id); wp_send_json($task); } }