/** * Changes the post_status of the given chat * * @author caseypatrickdriscoll * * @created 2015-08-27 15:13:52 * @edited 2015-08-28 17:58:30 - Refactors to prevent open and closed transient states * @edited 2015-08-28 18:14:09 - Adds fast update by returning user state on change_status * @edited 2015-08-28 20:38:24 - Adds auto comment for every status change * @edited 2015-08-29 18:45:34 - Adds PatchChat_Settings::status_change_message() for dynamic messages * */ public static function change_chat_status($chat) { // TODO: Assign agent when becomes 'open' // TODO: Create idea of assigned agents // TODO: Figure out security and sanitized stuff (although low priority as comes from select in admin POST) // TODO: Handle error situations, including missing data and error on update // TODO: Bulk status change in bulk editor // TODO: Style the selector based on status // TODO: Add thumbs up or signal if POST is success // 1. Update the post status and appropriate transients wp_update_post($chat); PatchChat_Transient::update($chat['ID'], 'status', $chat['post_status']); // 2. Add the comment $user = wp_get_current_user(); $options = array('chatid' => $chat['ID'], 'agentname' => $user->display_name, 'status' => $chat['post_status']); $comment = array('comment_type' => 'auto', 'comment_post_ID' => $chat['ID'], 'comment_content' => PatchChat_Settings::status_change_message($options)); if (self::add_comment($comment)) { return PatchChat_Controller::get_user_state(); } }