/** * (Re)open a ticket * * @since 3.3 * * @param $data * * @return void */ function wpas_admin_action_open_ticket($data) { if (!is_admin()) { return; } if (!isset($data['post'])) { return; } $post_id = (int) $data['post']; wpas_reopen_ticket($post_id); // Read-only redirect $redirect_to = add_query_arg(array('action' => 'edit', 'post' => $post_id, 'wpas-message' => 'opened'), admin_url('post.php')); wp_redirect(wp_sanitize_redirect($redirect_to)); exit; }
/** * Run pre-defined actions. * * Specific actions can be performed on page load. * Those actions are triggered by a URL parameter ($action). * * @since 3.0.0 * @return void */ public function custom_actions() { if (!isset($_GET['action'])) { return; } $action = sanitize_text_field($_GET['action']); switch ($action) { case 'reopen': if (isset($_GET['ticket_id'])) { wpas_reopen_ticket($_GET['ticket_id']); } wpas_redirect('ticket_reopen', add_query_arg(array('message' => '9'), get_permalink(intval($_GET['ticket_id']))), intval($_GET['ticket_id'])); exit; break; } }
/** * Run pre-defined actions. * * Specific actions can be performed on page load. * Those actions are triggered by a URL parameter ($action). * * @since 3.0.0 * @return void */ public function custom_actions() { if (!isset($_GET['action'])) { return; } $action = sanitize_text_field($_GET['action']); switch ($action) { case 'reopen': if (isset($_GET['ticket_id'])) { $ticket_id = filter_input(INPUT_GET, 'ticket_id', FILTER_SANITIZE_NUMBER_INT); 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; } break; } }
/** * 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; } }
/** * 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; }