Ejemplo n.º 1
0
 function test_wpas_get_replies()
 {
     $ticket_id = wpas_insert_ticket($this->ticket_data, false);
     $reply_id = wpas_insert_reply($this->reply_data, $ticket_id);
     $reply_id_2 = wpas_insert_reply($this->reply_data, $ticket_id);
     $replies = wpas_get_replies($ticket_id);
     $this->assertNotEmpty($replies);
     $this->assertCount(2, $replies);
 }
/**
 * Add a new reply to a ticket.
 *
 * @param array           $data      The reply data to insert
 * @param boolean|integer $parent_id ID of the parent ticket (post)
 * @param boolean|integer $author_id The ID of the reply author (false if none)
 *
 * @return boolean|integer False on failure or reply ID on success
 */
function wpas_add_reply($data, $parent_id = false, $author_id = false)
{
    if (false === $parent_id) {
        if (isset($data['parent_id'])) {
            /* Get the parent ID from $data if not provided in the arguments. */
            $parent_id = intval($data['parent_id']);
            $parent = get_post($parent_id);
            /* Mare sure the parent exists. */
            if (is_null($parent)) {
                return false;
            }
        } else {
            return false;
        }
    }
    /**
     * Submit the reply.
     *
     * Now that all the verifications are passed
     * we can proceed to the actual ticket submission.
     */
    $defaults = array('post_content' => '', 'post_name' => sprintf(__('Reply to ticket %s', 'awesome-support'), "#{$parent_id}"), 'post_title' => sprintf(__('Reply to ticket %s', 'awesome-support'), "#{$parent_id}"), 'post_status' => 'unread', 'post_type' => 'ticket_reply', 'ping_status' => 'closed', 'comment_status' => 'closed', 'post_parent' => $parent_id);
    $data = wp_parse_args($data, $defaults);
    if (false !== $author_id) {
        $data['post_author'] = $author_id;
    } else {
        global $current_user;
        $data['post_author'] = $current_user->ID;
    }
    $insert = wpas_insert_reply($data, $parent_id);
    return $insert;
}