/** * Attaches a ticket ID to a customer * * @access public * @since 1.0 */ public function attach_ticket($customer_id = 0, $ticket_id = 0) { $customer = new KBS_Customer($customer_id); if (empty($customer->id)) { return false; } // Attach the ticket, but don't increment stats, as this function previously did not return $customer->attach_ticket($ticket_id, false); }
/** * Create the base of a ticket. * * @since 1.0 * @return int|bool False on failure, the ticket ID on success. */ private function insert_ticket() { if (empty($this->ticket_title)) { $this->ticket_title = sprintf(__('New %s', 'kb-support'), kbs_get_ticket_label_singular()); } if (empty($this->ip)) { $this->ip = kbs_get_ip(); $this->pending['ip'] = $this->ip; } if (empty($this->key)) { $auth_key = defined('AUTH_KEY') ? AUTH_KEY : ''; $this->key = strtolower(md5($this->email . date('Y-m-d H:i:s') . $auth_key . uniqid('kbs', true))); // Unique key $this->pending['key'] = $this->key; } if (!empty($this->form_data)) { $this->pending['form_data'] = $this->form_data; } $ticket_data = array('date' => $this->date, 'agent' => $this->agent, 'user_email' => $this->email, 'user_info' => array('id' => $this->user_id, 'email' => $this->email, 'first_name' => $this->first_name, 'last_name' => $this->last_name), 'sla' => $this->sla, 'status' => $this->status, 'source' => $this->source, 'files' => $this->new_files, 'form_data' => $this->form_data); $args = apply_filters('kbs_insert_ticket_args', array('post_status' => $this->status, 'post_title' => $this->ticket_title, 'post_content' => $this->ticket_content, 'post_type' => 'kbs_ticket', 'post_date' => !empty($this->date) ? $this->date : null, 'post_date_gmt' => !empty($this->date) ? get_gmt_from_date($this->date) : null), $ticket_data); // Create a blank ticket $ticket_id = wp_insert_post($args); if (!empty($ticket_id)) { $this->ID = $ticket_id; $this->_ID = $ticket_id; $customer = new stdClass(); if (did_action('kbs_pre_process_ticket') && is_user_logged_in()) { $customer = new KBS_Customer(get_current_user_id(), true); // Customer is logged in but used a different email to log ticket with so assign to their customer record. if (!empty($customer->id) && $this->email != $customer->email) { $customer->add_email($this->email); } } if (empty($customer->id)) { $customer = new KBS_Customer($this->email); } if (empty($customer->id)) { $customer_data = array('name' => $this->first_name . ' ' . $this->last_name, 'email' => $this->email, 'user_id' => $this->user_id); $customer->create($customer_data); } $this->customer_id = $customer->id; $this->pending['customer_id'] = $this->customer_id; $customer->attach_ticket($this->ID); if (!empty($this->new_files)) { $this->pending['files'] = $this->new_files; } $this->pending['sla'] = $this->sla; $this->ticket_meta = apply_filters('kbs_ticket_meta', $this->ticket_meta, $ticket_data); $this->update_meta('_ticket_data', $this->ticket_meta); $this->new = true; } return $this->ID; }