function wpas_notify_close($ticket_id, $update, $user_id) { if (user_can($user_id, 'edit_ticket')) { $case = 'ticket_closed_agent'; } elseif (user_can($user_id, 'create_ticket')) { $case = 'ticket_closed_client'; } else { $case = 'ticket_closed'; } wpas_email_notify($ticket_id, $case); }
public function notify_close($ticket_id) { wpas_email_notify($ticket_id, 'ticket_closed'); }
/** * Save ticket custom fields. * * This function will save all custom fields associated * to the ticket post type. Be it core custom fields * or user added custom fields. * * @param (int) $post_id Current post ID * @since 3.0.0 */ public function save_ticket($post_id) { /* We should already being avoiding Ajax, but let's make sure */ if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE || wp_is_post_revision($post_id)) { return; } if (defined('DOING_AJAX') && DOING_AJAX) { return; } /* Now we check the nonce */ if (!isset($_POST[Awesome_Support_Admin::$nonce_name]) || !wp_verify_nonce($_POST[Awesome_Support_Admin::$nonce_name], Awesome_Support_Admin::$nonce_action)) { return; } /* Does the current user has permission? */ if (!current_user_can('edit_ticket', $post_id)) { return; } global $current_user, $wpas_cf; /** * Store possible logs */ $log = array(); /** * If no ticket status is found we are in the situation where * the agent is creating a ticket on behalf of the user. There are * a couple of things that we need to do then. */ if ('' === ($original_status = get_post_meta($post_id, '_wpas_status', true))) { /** * First of all, set the ticket as open. This is very important. */ add_post_meta($post_id, '_wpas_status', 'open', true); /** * Send the confirmation e-mail to the user. * * @since 3.1.5 */ wpas_email_notify($post_id, 'submission_confirmation'); } /* Save the possible ticket reply */ if (isset($_POST['wpas_reply']) && isset($_POST['wpas_reply_ticket']) && '' != $_POST['wpas_reply']) { /* Check for the nonce */ if (wp_verify_nonce($_POST['wpas_reply_ticket'], 'reply_ticket')) { $user_id = $current_user->ID; $content = wp_kses_post($_POST['wpas_reply']); $data = apply_filters('wpas_post_reply_admin_args', array('post_content' => $content, 'post_status' => 'read', 'post_type' => 'ticket_reply', 'post_author' => $user_id, 'post_parent' => $post_id, 'ping_status' => 'closed', 'comment_status' => 'closed')); /** * Remove the save_post hook now as we're going to trigger * a new one by inserting the reply (and logging the history later). */ remove_action('save_post_ticket', array($this, 'save_ticket')); /** * Fires right before a ticket reply is submitted * * @since 3.2.6 * * @param int $post_id Ticket ID * @param array $data Data to be inserted as the reply */ do_action('wpas_post_reply_admin_before', $post_id, $data); /* Insert the reply in DB */ $reply = wpas_add_reply($data, $post_id); /** * Fires right after a ticket reply is submitted * * @since 3.2.6 * * @param int $post_id Ticket ID * @param array $data Data to be inserted as the reply * @param bool|int Reply ID on success, false on failure */ do_action('wpas_post_reply_admin_after', $post_id, $data, $reply); /* In case the insertion failed... */ if (is_wp_error($reply)) { /* Set the redirection */ $_SESSION['wpas_redirect'] = add_query_arg(array('wpas-message' => 'wpas_reply_error'), get_permalink($post_id)); } else { /* E-Mail the client */ $new_reply = new WPAS_Email_Notification($post_id, array('reply_id' => $reply, 'action' => 'reply_agent')); /* The agent wants to close the ticket */ if (isset($_POST['wpas_do']) && 'reply_close' == $_POST['wpas_do']) { /* Confirm the post type and close */ if ('ticket' == get_post_type($post_id)) { /** * wpas_ticket_before_close_by_agent hook */ do_action('wpas_ticket_before_close_by_agent', $post_id); /* Close */ $closed = wpas_close_ticket($post_id); /* E-Mail the client */ new WPAS_Email_Notification($post_id, array('action' => 'closed')); /** * wpas_ticket_closed_by_agent hook */ do_action('wpas_ticket_closed_by_agent', $post_id); } } } } } /* Now we can save the custom fields */ $wpas_cf->save_custom_fields($post_id, $_POST); /* Log the action */ if (!empty($log)) { wpas_log($post_id, $log); } /* If this was a ticket update, we need to know where to go now... */ if ('' !== $original_status) { /* Go back to the tickets list */ if (isset($_POST['wpas_back_to_list']) && true === boolval($_POST['wpas_back_to_list']) || isset($_POST['where_after']) && 'back_to_list' === $_POST['where_after']) { $_SESSION['wpas_redirect'] = add_query_arg(array('post_type' => 'ticket'), admin_url('edit.php')); } } }