/** * 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 */ public function redirect_archive() { if (is_post_type_archive('ticket')) { wpas_redirect('archive_redirect', get_permalink(wpas_get_option('ticket_list'))); } }
/** * 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 */ public function redirect_archive() { if (is_post_type_archive('ticket')) { wpas_redirect('archive_redirect', wpas_get_tickets_list_page_url()); } }
/** * Execute plugin custom actions. * * Any custom actions the plugin can trigger through a URL variable * will be executed here. It is all triggered by the var wpas-do. * * @since 3.0.0 */ public function custom_actions() { /* Make sure we have a trigger */ if (!isset($_GET['wpas-do'])) { return; } /* Validate the nonce */ if (!isset($_GET['wpas-nonce']) || !wp_verify_nonce($_GET['wpas-nonce'], 'wpas_custom_action')) { return; } $log = array(); $action = sanitize_text_field($_GET['wpas-do']); switch ($action) { case 'close': if (isset($_GET['post']) && 'ticket' == get_post_type(intval($_GET['post']))) { $url = add_query_arg(array('post' => $_GET['post'], 'action' => 'edit', 'wpas-message' => 'closed'), admin_url('post.php')); wpas_close_ticket($_GET['post']); } break; case 'open': if (isset($_GET['post']) && 'ticket' == get_post_type(intval($_GET['post']))) { $url = add_query_arg(array('post' => $_GET['post'], 'action' => 'edit', 'wpas-message' => 'opened'), admin_url('post.php')); wpas_reopen_ticket($_GET['post']); } break; case 'trash_reply': if (isset($_GET['del_id']) && current_user_can('delete_reply')) { $del_id = intval($_GET['del_id']); /* Trash the post */ wp_trash_post($del_id, false); /* Redirect with clean URL */ $url = wp_sanitize_redirect(add_query_arg(array('post' => $_GET['post'], 'action' => 'edit'), admin_url('post.php') . "#wpas-post-{$del_id}")); wpas_redirect('trashed_reply', $url); exit; } break; case 'multiple-products': $options = maybe_unserialize(get_option('wpas_options')); $options['support_products'] = '1'; update_option('wpas_options', serialize($options)); delete_option('wpas_support_products'); wpas_redirect('enable_multiple_products', add_query_arg(array('taxonomy' => 'product', 'post_type' => 'ticket'), admin_url('edit-tags.php'))); exit; break; case 'single-product': delete_option('wpas_support_products'); wpas_redirect('enable_single_product', remove_query_arg(array('wpas-nonce', 'wpas-do'), wpas_get_current_admin_url())); exit; break; } /** * wpas_custom_actions hook * * Fired right after the action is executed. It is important to note that * some of the action are triggering a redirect after they're done and * that in this case this hook won't be triggered. * * @param string $action The action that's being executed */ do_action('wpas_execute_custom_action', $action); /* Log the action */ if (!empty($log)) { wpas_log($_GET['post'], $log); } /* Get URL vars */ $args = $_GET; /* Remove custom action and nonce */ unset($_GET['wpas-do']); unset($_GET['wpas-nonce']); /* Read-only redirect */ wpas_redirect('read_only', $url); exit; }
/** * Trigger the re-open ticket function * * This is triggered by the wpas_do custom actions. * * @since 3.3 * * @param array $data Superglobal data * * @return void */ function wpas_reopen_ticket_trigger($data) { if (isset($data['ticket_id'])) { $ticket_id = (int) $data['ticket_id']; if (!wpas_can_submit_ticket($ticket_id) && !current_user_can('edit_ticket')) { wpas_add_error('cannot_reopen_ticket', __('You are not allowed to re-open this ticket', 'awesome-support')); wpas_redirect('ticket_reopen', wpas_get_tickets_list_page_url()); exit; } wpas_reopen_ticket($ticket_id); wpas_add_notification('ticket_reopen', __('The ticket has been successfully re-opened.', 'awesome-support')); wpas_redirect('ticket_reopen', wp_sanitize_redirect(get_permalink($ticket_id))); exit; } }
/** * 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); } }