/** * Adds a PatchChat_Transient to a transient's array * * @author caseypatrickdriscoll * * @created 2015-07-19 20:18:54 * @edited 2015-08-04 16:13:17 - Refactors to build all given arrays * * $transient_name string The name of the transient to add to ('patchchat_new', etc) * * $patchchat array The array of information to store in transient (see 'Form' in class comments) * */ public static function add($state_name, $transient) { $transient_state = PatchChat_Transient_State::get($state_name); array_unshift($transient_state, $transient); PatchChat_Transient_State::set($state_name, $transient_state); return true; }
/** * Returns the given agent's transient set along with the new chats * * @author caseypatrickdriscoll * * @edited 2015-08-04 15:36:31 - Adds role check for getting user chats * @edited 2015-08-27 18:38:05 - Refactors to remove get_array() * @edited 2015-08-29 18:16:26 - Refactors for situations with no user_id because the user was just created * * TODO: Add 'agent' role/capability instead of 'administrator' */ public static function get_user_state($user_id = NULL) { if ($user_id == NULL) { $user = wp_get_current_user(); $user_id = $user->ID; } else { $user = get_user_by('id', $user_id); } $user_chats = PatchChat_Transient_State::get($user_id); if (!empty($user->roles) && is_array($user->roles)) { foreach ($user->roles as $role) { if ($role == 'administrator') { $user_chats = array_merge($user_chats, PatchChat_Transient_State::get('new')); } } } return $user_chats; }