<tbody> <?php while ($wpas_tickets->have_posts()) { $wpas_tickets->the_post(); echo '<tr>'; foreach ($columns as $column_id => $column) { echo '<td'; /* If current column is the date we add the date attribute for sorting purpose */ if ('date' === $column_id) { echo ' data-order="' . strtotime(get_the_time()) . '"'; } /* We don't forget to close the <td> tag */ echo '>'; /* Display the content for this column */ wpas_get_tickets_list_column_content($column_id, $column); echo '</td>'; } echo '</tr>'; } wp_reset_query(); ?> </tbody> </table> <?php wpas_make_button(__('Open a ticket', 'awesome-support'), array('type' => 'link', 'link' => wpas_get_submission_page_url(), 'class' => 'wpas-btn wpas-btn-default')); ?> </div> <?php } else { echo wpas_get_notification_markup('info', sprintf(__('You haven\'t submitted a ticket yet. <a href="%s">Click here to submit your first ticket</a>.', 'awesome-support'), wpas_get_submission_page_url())); }
/** * 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); }
<tr> <td class="row-title">Ticket Submission</td> <?php $page_submit = wpas_get_option('ticket_submit'); ?> <td> <?php if (empty($page_submit)) { echo '<span class="wpas-alert-danger">Not set</span>'; } else { $submission_pages = array(); if (!is_array($page_submit)) { $page_submit = (array) $page_submit; } foreach ($page_submit as $page_submit_id) { $page_submit_url = wpas_get_submission_page_url($page_submit_id); array_push($submission_pages, "<span class='wpas-alert-success'>" . esc_url($page_submit_url) . " (#{$page_submit_id})</span>"); } echo implode(', ', $submission_pages); } ?> </td> </tr> <tr> <td class="row-title">Tickets List</td> <?php $page_list = wpas_get_option('ticket_list'); if (is_array($page_list) && !empty($page_list)) { $page_list = $page_list[0]; } ?>
/** * Redirect ticket archive page. * * We don't use the archive page to display the ticket * so let's redirect it to the user's tickets list instead. * * @since 1.0.0 * @return void */ function wpas_redirect_ticket_archive() { if (is_post_type_archive('ticket')) { // Redirect to the tickets list page $redirect_to = wpas_get_tickets_list_page_url(); // Fallback to the ticket submission page if (empty($redirect_to)) { $redirect_to = wpas_get_submission_page_url(); } // Fallback to the site homepage if (empty($redirect_to)) { $redirect_to = home_url(); } wpas_redirect('archive_redirect', $redirect_to); } }
<div class="wpas-ticket-buttons-top"> <?php wpas_make_button(__('My Tickets', 'awesome-support'), array('type' => 'link', 'link' => wpas_get_tickets_list_page_url(), 'class' => 'wpas-btn wpas-btn-default wpas-link-ticketlist')); ?> <?php wpas_make_button(__('Open a ticket', 'awesome-support'), array('type' => 'link', 'link' => wpas_get_submission_page_url(), 'class' => 'wpas-btn wpas-btn-default wpas-link-ticketnew')); ?> <?php wpas_make_button(__('Logout', 'awesome-support'), array('type' => 'link', 'link' => wp_logout_url(), 'class' => 'wpas-btn wpas-btn-default wpas-link-logout')); ?> </div>