/** * Update the open agent tickets count when a ticket is transferred from one agent to another * * We do not need to add a new ticket to the new agent because it is automatically done in wpas_assign_ticket() * * @since 3.2.8 * * @param int $agent_id ID of the current ticket assignee * @param int $previous_agent_id ID of the previous assignee * * @return void */ function wpas_update_ticket_count_on_transfer($agent_id, $previous_agent_id) { $agent_prev = new WPAS_Member_Agent($previous_agent_id); $agent_prev->ticket_minus(); }
/** * Change a ticket status to closed. * * @since 3.0.2 * * @param integer $ticket_id ID of the ticket to close * @param int $user_id ID of the user who closed the ticket * * @return integer|boolean ID of the post meta if exists, true on success or false on failure */ function wpas_close_ticket($ticket_id, $user_id = 0) { global $current_user; // Set the user who closed the ticket to the current user if nothing is specified if (0 === $user_id) { $user_id = $current_user->ID; } if (!current_user_can('close_ticket')) { wp_die(__('You do not have the capacity to close this ticket', 'awesome-support'), __('Can’t close ticket', 'awesome-support'), array('back_link' => true)); } $ticket_id = intval($ticket_id); if ('ticket' == get_post_type($ticket_id)) { $update = update_post_meta(intval($ticket_id), '_wpas_status', 'closed'); /* Decrement the number of tickets open for this agent */ $agent_id = get_post_meta($ticket_id, '_wpas_assignee', true); $agent = new WPAS_Member_Agent($agent_id); $agent->ticket_minus(); /* Log the action */ wpas_log($ticket_id, __('The ticket was closed.', 'awesome-support')); /** * wpas_after_close_ticket hook * * @since 3.0.0 */ do_action('wpas_after_close_ticket', $ticket_id, $update, $user_id); if (is_admin()) { /** * Fires after the ticket was closed in the admin only. * * @since 3.1.2 * * @param integer $ticket_id ID of the ticket we just closed * @param integer $user_id ID of the user who did the action * @param boolean $update True on success, false on fialure */ do_action('wpas_after_close_ticket_admin', $ticket_id, $user_id, $update); } else { /** * Fires after the ticket was closed in the front-end only. * * @since 3.1.2 * * @param integer $ticket_id ID of the ticket we just closed * @param integer $user_id ID of the user who did the action * @param boolean $update True on success, false on failure */ do_action('wpas_after_close_ticket_public', $ticket_id, $user_id, $update); } return $update; } else { return false; } }
/** * Delete ticket dependencies. * * Delete all ticket dependencies when a ticket is deleted. This includes * ticket replies and ticket history. Ticket attachments are deleted by * WPAS_File_Upload::delete_attachments() * * @param integer $post_id ID of the post to be deleted * * @return void */ function wpas_delete_ticket_dependencies($post_id) { global $post_type; if ('ticket' !== $post_type) { return; } /* First of all we remove this action to avoid creating a loop */ remove_action('before_delete_post', 'wpas_delete_ticket_dependencies', 10); $args = array('post_parent' => $post_id, 'post_type' => apply_filters('wpas_replies_post_type', array('ticket_history', 'ticket_reply')), 'post_status' => 'any', 'posts_per_page' => -1, 'no_found_rows' => true, 'cache_results' => false, 'update_post_term_cache' => false, 'update_post_meta_cache' => false); $posts = new WP_Query($args); foreach ($posts->posts as $id => $post) { do_action('wpas_before_delete_dependency', $post->ID, $post); wp_delete_post($post->ID, true); do_action('wpas_after_delete_dependency', $post->ID, $post); } /* Decrement the number of tickets open for this agent */ $agent_id = get_post_meta($post_id, '_wpas_assignee', true); $agent = new WPAS_Member_Agent($agent_id); $agent->ticket_minus(); }