/**
  * Setup the ticket properties.
  *
  * @since	1.0
  * @param 	int		$ticket_id	The Ticket ID
  * @return	bool	True if the setup was successful
  */
 private function setup_ticket($ticket_id)
 {
     $this->pending = array();
     if (empty($ticket_id)) {
         return false;
     }
     $ticket = get_post($ticket_id);
     if (!$ticket || is_wp_error($ticket)) {
         return false;
     }
     if ('kbs_ticket' !== $ticket->post_type) {
         return false;
     }
     // Extensions can hook here perform actions before the ticket data is loaded
     do_action('kbs_pre_setup_ticket', $this, $ticket_id);
     // Primary Identifier
     $this->ID = absint($ticket_id);
     // Protected ID that can never be changed
     $this->_ID = absint($ticket_id);
     // We have a ticket, get the generic ticket_meta item to reduce calls to it
     $this->ticket_meta = $this->get_meta();
     // Status and Dates
     $this->date = $ticket->post_date;
     $this->modified_date = $ticket->post_modified;
     $this->completed_date = $this->setup_completed_date();
     $this->status = $ticket->post_status;
     $this->post_status = $this->status;
     $all_ticket_statuses = kbs_get_ticket_statuses();
     $this->status_nicename = array_key_exists($this->status, $all_ticket_statuses) ? $all_ticket_statuses[$this->status] : ucfirst($this->status);
     // Content & Replies
     $this->ticket_title = $ticket->post_title;
     $this->ticket_content = $ticket->post_content;
     $this->replies = kbs_get_ticket_replies($this->ID);
     $this->files = $this->get_files();
     // User data
     $this->ip = $this->setup_ip();
     $this->agent = $this->setup_agent_id();
     $this->customer_id = $this->setup_customer_id();
     $this->user_id = $this->setup_user_id();
     $this->email = $this->setup_email();
     $this->user_info = $this->setup_user_info();
     $this->first_name = $this->user_info['first_name'];
     $this->last_name = $this->user_info['last_name'];
     // SLA
     $this->sla = $this->setup_sla();
     $this->key = $this->setup_ticket_key();
     $this->form_data = $this->setup_form_data();
     // Extensions can hook here to add items to this object
     do_action('kbs_setup_ticket', $this, $ticket_id);
     return true;
 }
/**
 * Display replies for ticket post metabox.
 *
 * @since	1.0
 * @return	str
 */
function kbs_ajax_display_ticket_replies()
{
    $output = '';
    if (!empty($_POST['kbs_reply_id'])) {
        $output .= kbs_ticket_get_reply_html($_POST['kbs_reply_id'], $_POST['kbs_ticket_id']);
    } else {
        $replies = kbs_get_ticket_replies($_POST['kbs_ticket_id']);
        if (!empty($replies)) {
            foreach ($replies as $reply) {
                $output .= kbs_ticket_get_reply_html($reply, $_POST['kbs_ticket_id']);
            }
        }
    }
    echo $output;
    die;
}