static function ajax_save() { if (!isset($_POST[Kanban_Utils::get_nonce()]) || !wp_verify_nonce($_POST[Kanban_Utils::get_nonce()], sprintf('%s-save', Kanban::get_instance()->settings->basename)) || !is_user_logged_in()) { wp_send_json_error(); } do_action(sprintf('%s_before_%s_ajax_save', Kanban::get_instance()->settings->basename, self::$slug)); $status_id_old = Kanban_Utils::format_key(self::$slug, 'status_id_old'); $status_id_new = Kanban_Utils::format_key(self::$slug, 'status_id_new'); // build post data $post_data = array('post_type' => Kanban_Post_Types::format_post_type(self::$slug), 'post_title' => sprintf('changed task ID %s from %s to %s', $_POST['task_id'], $_POST['status_id_old'], $_POST['status_id_new']), 'post_parent' => $_POST['task_id'], 'postmeta' => array($status_id_old => $_POST['status_id_old'], $status_id_new => $_POST['status_id_new']), 'terms' => array()); // save our work_hour $post_data = Kanban_Post::save($post_data); if (!$post_data) { wp_send_json_error(); } do_action(sprintf('%s_after_%s_ajax_save', Kanban::get_instance()->settings->basename, self::$slug)); wp_send_json_success(array('message' => sprintf('%s saved', self::$slug), self::$slug => $post_data)); }
static function ajax_save() { if (!isset($_POST[Kanban_Utils::get_nonce()]) || !wp_verify_nonce($_POST[Kanban_Utils::get_nonce()], sprintf('%s-save', Kanban::get_instance()->settings->basename)) || $_POST['post_type'] !== Kanban_Post_Types::format_post_type(self::$slug) || !is_user_logged_in()) { wp_send_json_error(); } do_action(sprintf('%s_before_%s_ajax_save', Kanban::get_instance()->settings->basename, self::$slug)); if (!isset($_POST[self::$slug]['post_type'])) { $post_type = Kanban_Post_Types::format_post_type(self::$slug); $_POST['post_type'] = $post_type; } $post_data = Kanban_Post::save($_POST); if (!$post_data) { wp_send_json_error(); } do_action(sprintf('%s_after_%s_ajax_save', Kanban::get_instance()->settings->basename, self::$slug)); wp_send_json_success(array('message' => sprintf('%s saved', self::$slug), self::$slug => $post_data)); }
static function ajax_save() { if (!isset($_POST[Kanban_Utils::get_nonce()]) || !wp_verify_nonce($_POST[Kanban_Utils::get_nonce()], sprintf('%s-save', Kanban::get_instance()->settings->basename)) || !is_user_logged_in()) { wp_send_json_error(); } do_action(sprintf('%s_before_%s_ajax_save', Kanban::get_instance()->settings->basename, self::$slug)); $current_user_id = get_current_user_id(); $comment_type_field = Kanban_Utils::format_key(self::$slug, 'comment_type'); // build post data $post_data = array('post_type' => Kanban_Post_Types::format_post_type(self::$slug), 'post_title' => sprintf('%s comment for task %s', $_POST['comment_type'], $_POST['id']), 'post_content' => sanitize_text_field(str_replace("\n", '', $_POST['post_content'])), 'post_parent' => $_POST['id'], 'postmeta' => array($comment_type_field => $_POST['comment_type'])); // save our work_hour $post_data = Kanban_Post::save($post_data); if (!$post_data) { wp_send_json_error(); } do_action(sprintf('%s_after_%s_ajax_save', Kanban::get_instance()->settings->basename, self::$slug)); wp_send_json_success(array('message' => sprintf('%s saved', self::$slug), self::$slug => $post_data)); }
static function ajax_save() { if (!isset($_POST[Kanban_Utils::get_nonce()]) || !wp_verify_nonce($_POST[Kanban_Utils::get_nonce()], sprintf('%s-save', Kanban::$instance->settings->basename)) || !isset($_POST[Kanban_Task::$slug]) || !is_user_logged_in()) { wp_send_json_error(); } do_action(sprintf('%s_before_%s_ajax_save', Kanban::$instance->settings->basename, self::$slug)); // build post data $post_data = array('post_type' => Kanban_Post_Types::format_post_type('work_hour'), 'post_title' => sanitize_text_field($_POST[Kanban_Task::$slug]['post_title']), 'postmeta' => array(), 'terms' => array()); $hour_operator = Kanban_Utils::format_key('work_hour', 'operator'); $post_data['postmeta'][$hour_operator] = $_POST['operator']; // set assignee as author of work hour $task_user_id_assigned_to = Kanban_Utils::format_key('task', 'user_id_assigned'); if ($_POST[Kanban_Task::$slug]['postmeta'][$task_user_id_assigned_to] > 0) { $post_data['post_author'] = $_POST[Kanban_Task::$slug]['postmeta'][$task_user_id_assigned_to]; } // link task to hour $hour_task_id = Kanban_Utils::format_key('work_hour', 'project_id'); $post_data['postmeta'][$hour_task_id] = $_POST[Kanban_Task::$slug]['ID']; // link current user to hour $hour_user_id_logged = Kanban_Utils::format_key('work_hour', 'user_id_logged'); $post_data['postmeta'][$hour_user_id_logged] = get_current_user_id(); // set task project as work project $task_project_id = Kanban_Utils::format_key('task', 'project_id'); $hour_project_id = Kanban_Utils::format_key('work_hour', 'project_id'); $post_data['postmeta'][$hour_project_id] = $_POST[Kanban_Task::$slug]['postmeta'][$task_project_id]; // set current task status for work hour $task_status = Kanban_Utils::format_key('task', 'status'); $hour_status_id = Kanban_Utils::format_key('work_hour', 'task_status_id'); $post_data['postmeta'][$hour_status_id] = $_POST[Kanban_Task::$slug]['terms'][$task_status][0]; // save our work_hour $post_data = Kanban_Post::save($post_data); if (!$post_data) { wp_send_json_error(); } do_action(sprintf('%s_after_%s_ajax_save', Kanban::$instance->settings->basename, self::$slug)); wp_send_json_success(array('message' => sprintf('%s saved', self::$slug), self::$slug => $post_data)); }