예제 #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);
 }
 function setUp()
 {
     parent::setUp();
     /**
      * Add a text field.
      */
     wpas_add_custom_field('my_test_field', array('field_type' => 'text', 'capability' => 'create_ticket', 'sanitize' => 'sanitize_text_field', 'title' => 'Test Field', 'html5_pattern' => ''));
     /**
      * Add a test ticket.
      */
     $this->ticket_id = wpas_insert_ticket(array('post_title' => 'Test Ticket', 'post_name' => 'Test Ticket', 'post_author' => 1, 'post_content' => 'In hac habitasse platea dictumst. Nulla neque dolor, sagittis eget, iaculis quis, molestie non, velit. Nullam cursus lacinia erat. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Donec vitae orci sed dolor rutrum auctor.'), false);
     /**
      * Get all the custom fields.
      */
     $this->fields = WPAS()->custom_fields->get_custom_fields();
     /**
      * Instantiate the custom fields objects.
      */
     $this->text_field = new WPAS_Custom_Field('my_test_field', $this->fields['my_test_field']);
 }
/**
 * Open a new ticket.
 *
 * @since  3.0.0
 * @param  array $data Ticket data
 * @return boolean
 */
function wpas_open_ticket($data)
{
    $title = isset($data['title']) ? wp_strip_all_tags($data['title']) : false;
    $content = isset($data['message']) ? wp_kses($data['message'], wp_kses_allowed_html('post')) : false;
    /**
     * Prepare vars
     */
    $submit = isset($_POST['_wp_http_referer']) ? wpas_get_submission_page_url(url_to_postid($_POST['_wp_http_referer'])) : wpas_get_submission_page_url();
    // Fallback in case the referrer failed
    if (empty($submit)) {
        $submission_pages = wpas_get_option('ticket_submit');
        $submit = $submission_pages[0];
        $submit = wp_sanitize_redirect(get_permalink($submit));
    }
    // Verify user capability
    if (!current_user_can('create_ticket')) {
        // Save the input
        wpas_save_values();
        // Redirect to submit page
        wpas_add_error('cannot_open_ticket', __('You do not have the capacity to open a new ticket.', 'awesome-support'));
        wp_redirect($submit);
        // Break
        exit;
    }
    // Make sure we have at least a title and a message
    if (false === $title || empty($title)) {
        // Save the input
        wpas_save_values();
        // Redirect to submit page
        wpas_add_error('missing_title', __('It is mandatory to provide a title for your issue.', 'awesome-support'));
        wp_redirect($submit);
        // Break
        exit;
    }
    if (true === ($description_mandatory = apply_filters('wpas_ticket_submission_description_mandatory', true)) && (false === $content || empty($content))) {
        // Save the input
        wpas_save_values();
        // Redirect to submit page
        wpas_add_error('missing_description', __('It is mandatory to provide a description for your issue.', 'awesome-support'));
        wp_redirect($submit);
        // Break
        exit;
    }
    /**
     * Allow the submission.
     *
     * This variable is used to add additional checks in the submission process.
     * If the $go var is set to true, it gives a green light to this method
     * and the ticket will be submitted. If the var is set to false, the process
     * will be aborted.
     *
     * @since  3.0.0
     */
    $go = apply_filters('wpas_before_submit_new_ticket_checks', true);
    /* Check for the green light */
    if (is_wp_error($go)) {
        /* Retrieve error messages. */
        $messages = $go->get_error_messages();
        /* Save the input */
        wpas_save_values();
        /* Redirect to submit page */
        wpas_add_error('validation_issue', $messages);
        wp_redirect($submit);
        exit;
    }
    /**
     * Gather current user info
     */
    if (is_user_logged_in()) {
        global $current_user;
        $user_id = $current_user->ID;
    } else {
        // Save the input
        wpas_save_values();
        // Redirect to submit page
        wpas_add_error('unknown_user', __('Only registered accounts can submit a ticket. Please register first.', 'awesome-support'));
        wp_redirect($submit);
        exit;
    }
    /**
     * Submit the ticket.
     *
     * Now that all the verifications are passed
     * we can proceed to the actual ticket submission.
     */
    $post = apply_filters('wpas_open_ticket_data', array('post_content' => $content, 'post_name' => $title, 'post_title' => $title, 'post_status' => 'queued', 'post_type' => 'ticket', 'post_author' => $user_id, 'ping_status' => 'closed', 'comment_status' => 'closed'));
    return wpas_insert_ticket($post, false, false);
}
예제 #4
0
/**
 * Open a new ticket.
 *
 * @since  3.0.0
 * @param  array $data Ticket data
 * @return boolean
 */
function wpas_open_ticket($data)
{
    $title = isset($data['title']) ? wp_strip_all_tags($data['title']) : false;
    $content = isset($data['message']) ? wp_kses($data['message'], wp_kses_allowed_html('post')) : false;
    /**
     * Prepare vars
     */
    $submit = wpas_get_option('ticket_submit');
    // ID of the submission page
    // Verify user capability
    if (!current_user_can('create_ticket')) {
        // Save the input
        wpas_save_values();
        // Redirect to submit page
        wp_redirect(add_query_arg(array('message' => 11), get_permalink($submit)));
        // Break
        exit;
    }
    // Make sure we have at least a title and a message
    if (false === $title || empty($title)) {
        // Save the input
        wpas_save_values();
        // Redirect to submit page
        wp_redirect(add_query_arg(array('message' => 3), get_permalink($submit)));
        // Break
        exit;
    }
    if (true === ($description_mandatory = apply_filters('wpas_ticket_submission_description_mandatory', true)) && (false === $content || empty($content))) {
        // Save the input
        wpas_save_values();
        // Redirect to submit page
        wp_redirect(add_query_arg(array('message' => 10), get_permalink($submit)));
        // Break
        exit;
    }
    /**
     * Allow the submission.
     *
     * This variable is used to add additional checks in the submission process.
     * If the $go var is set to true, it gives a green light to this method
     * and the ticket will be submitted. If the var is set to false, the process
     * will be aborted.
     *
     * @since  3.0.0
     */
    $go = apply_filters('wpas_before_submit_new_ticket_checks', true);
    /* Check for the green light */
    if (is_wp_error($go)) {
        /* Retrieve error messages. */
        $messages = $go->get_error_messages();
        /* Save the input */
        wpas_save_values();
        /* Redirect to submit page */
        wp_redirect(add_query_arg(array('message' => wpas_create_notification($messages)), get_permalink($submit)));
        exit;
    }
    /**
     * Gather current user info
     */
    if (is_user_logged_in()) {
        global $current_user;
        $user_id = $current_user->ID;
    } else {
        // Save the input
        wpas_save_values();
        // Redirect to submit page
        wp_redirect(add_query_arg(array('message' => 5), get_permalink($submit)));
        // Break
        exit;
    }
    /**
     * Submit the ticket.
     *
     * Now that all the verifications are passed
     * we can proceed to the actual ticket submission.
     */
    $post = array('post_content' => $content, 'post_name' => $title, 'post_title' => $title, 'post_status' => 'queued', 'post_type' => 'ticket', 'post_author' => $user_id, 'ping_status' => 'closed', 'comment_status' => 'closed');
    return wpas_insert_ticket($post, false, false);
}