/** * 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(); } }
/** * Sets the transient by chat_id * * Also responsible for pushing the updates to the respective Transient States * * In theory, this should be the only method that updates any PatchChat_Transient_State * * @author caseypatrickdriscoll * * @created 2015-08-27 18:59:19 * @edited 2015-08-28 12:30:12 - Refactors to push transient updates to state without move function * @edited 2015-08-29 13:57:00 - Adds bot for auto comments */ public static function set($chat_id, $transient, $update_state = 1) { // 1. Set the individual chat transient set_transient('patchchat_' . $chat_id, $transient); if (!$update_state) { return; } // 2. Update all the 'new' transient state, which is an outlier if ($transient['status'] == 'new') { PatchChat_Transient_State::update('new', $transient); } else { PatchChat_Transient_State::trim('new', $chat_id); } // 3. Update all the individual user transients foreach ($transient['users'] as $user_id => $user) { if ($user_id == PatchChat_Settings::bot()) { continue; } PatchChat_Transient_State::update($user_id, $transient); } }
/** * Loads the scripts and styles for admin table * * @author caseypatrickdriscoll * * @created 2015-07-18 17:51:00 */ static function load_back_assets() { PatchChat::register_assets(); // TODO: Not sure I like 'patchchat_messenger' but the patchchat cpt took over the menu. // The original 'patchchat' admin menu is not linked if (isset($_GET['post_type']) && $_GET['post_type'] == 'patchchat') { wp_enqueue_style('patchchat-admintable', plugins_url('/assets/css/admintable.css', __FILE__)); wp_enqueue_script('patchchat-admintable', plugins_url('/assets/js/admintable.js', __FILE__), array('jquery'), '', true); } else { if (isset($_GET['page']) && $_GET['page'] == 'patchchat') { wp_enqueue_style('patchchat-back', plugins_url('/assets/css/patchchat-back.css', __FILE__), array('font-awesome')); wp_enqueue_script('patchchat-back', plugins_url('/assets/js/patchchat-back.js', __FILE__), array('jquery', 'react-with-addons', 'patchchat'), '', true); wp_localize_script('patchchat-back', 'patchchat', PatchChat_Settings::localize()); wp_enqueue_script('bootstrap-tabs', plugins_url('/assets/js/bootstrap.tabs.min.js', __FILE__)); } else { if (isset($_GET['page']) && $_GET['page'] == 'patchchat_settings') { wp_enqueue_script('patchchat-settings'); wp_localize_script('patchchat-settings', 'patchchat', array('audiourl' => plugins_url('/assets/audio/', __FILE__))); wp_enqueue_style('font-awesome'); } } } wp_enqueue_style('cmb2'); }