| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package Awesome Support/Admin/Functions/Ajax |
| 4 |
* @author AwesomeSupport <contact@getawesomesupport.com> |
| 5 |
* @license GPL-2.0+ |
| 6 |
* @link https://getawesomesupport.com |
| 7 |
* @copyright 2015-2017 AwesomeSupport |
| 8 |
*/ |
| 9 |
|
| 10 |
// If this file is called directly, abort. |
| 11 |
if ( ! defined( 'WPINC' ) ) { |
| 12 |
die; |
| 13 |
} |
| 14 |
|
| 15 |
add_action( 'wp_ajax_wpas_dismiss_free_addon_page', 'wpas_dismiss_free_addon_page' ); |
| 16 |
/** |
| 17 |
* Hide the free addon page from the menu |
| 18 |
* |
| 19 |
* @since 3.3.3 |
| 20 |
* @return bool |
| 21 |
*/ |
| 22 |
function wpas_dismiss_free_addon_page() { |
| 23 |
check_ajax_referer('wpas_admin_optin', 'nonce'); |
| 24 |
if ( ! current_user_can( 'manage_options' ) ) { |
| 25 |
wp_send_json_error( array('message' => __('Unauthorized action. You do not have permission to hide the free addon page from the menu.', 'awesome-support') ), 403); |
| 26 |
} |
| 27 |
return add_option( 'wpas_dismiss_free_addon_page', true ); |
| 28 |
} |
| 29 |
|
| 30 |
add_action( 'wp_ajax_wpas_skip_wizard_setup', 'wpas_skip_wizard_setup' ); |
| 31 |
/** |
| 32 |
* Skip Setup Wizard |
| 33 |
* |
| 34 |
* @since 3.3.3 |
| 35 |
* @return bool |
| 36 |
*/ |
| 37 |
function wpas_skip_wizard_setup() { |
| 38 |
check_ajax_referer('wpas_admin_wizard', 'nonce'); |
| 39 |
if ( ! current_user_can( 'manage_options' ) ) { |
| 40 |
wp_send_json_error( array('message' => __('Unauthorized action. You do not have permission to skip Setup Wizard.', 'awesome-support') ), 403); |
| 41 |
} |
| 42 |
add_option( 'wpas_skip_wizard_setup', true ); |
| 43 |
wp_die(); |
| 44 |
} |
| 45 |
|
| 46 |
add_action( 'wp_ajax_wpas_get_ticket_for_print', 'wpas_get_ticket_for_print_ajax' ); |
| 47 |
/** |
| 48 |
* Get ticket for print |
| 49 |
* |
| 50 |
* @since 5.1.1 |
| 51 |
* |
| 52 |
* @return void |
| 53 |
*/ |
| 54 |
function wpas_get_ticket_for_print_ajax() { |
| 55 |
|
| 56 |
check_ajax_referer( 'wpas_print_ticket', 'nonce' ); |
| 57 |
if ( ! current_user_can( 'edit_ticket' ) ) { |
| 58 |
wp_send_json_error( array('message' => __('Unauthorized action. You do not have permission to get ticket for print.', 'awesome-support') ), 403); |
| 59 |
} |
| 60 |
$ticket = isset( $_POST['id'] ) ? wpas_get_ticket_by_id( sanitize_text_field( wp_unslash( $_POST['id'] ) ) ) : null; |
| 61 |
|
| 62 |
if ( ! empty( $ticket ) ) { |
| 63 |
|
| 64 |
$replies = wpas_get_replies( $ticket->ID, 'any', [ |
| 65 |
'posts_per_page' => - 1, |
| 66 |
'orderby' => 'post_date', |
| 67 |
'order' => wpas_get_option( 'replies_order', 'ASC' ), |
| 68 |
'post_type' => apply_filters( 'wpas_replies_post_type', [ |
| 69 |
'ticket_history', |
| 70 |
'ticket_reply' |
| 71 |
] ), |
| 72 |
'post_parent' => $ticket->ID, |
| 73 |
'post_status' => apply_filters( 'wpas_replies_post_status', [ |
| 74 |
'publish', |
| 75 |
'inherit', |
| 76 |
'private', |
| 77 |
'trash', |
| 78 |
'read', |
| 79 |
'unread' |
| 80 |
] ) |
| 81 |
] ); |
| 82 |
|
| 83 |
include WPAS_PATH . 'includes/admin/views/print-ticket.php'; |
| 84 |
|
| 85 |
} else { |
| 86 |
|
| 87 |
esc_html_e( 'Ticket not found', 'awesome-support' ); |
| 88 |
|
| 89 |
} |
| 90 |
|
| 91 |
wp_die(); |
| 92 |
|
| 93 |
} |
| 94 |
|
| 95 |
add_action( 'wp_ajax_wpas_get_tickets_for_print', 'wpas_get_tickets_for_print_ajax' ); |
| 96 |
/** |
| 97 |
* Get tickets for print |
| 98 |
* |
| 99 |
* @since 5.1.1 |
| 100 |
* |
| 101 |
* @return void |
| 102 |
*/ |
| 103 |
function wpas_get_tickets_for_print_ajax() { |
| 104 |
|
| 105 |
check_ajax_referer( 'wpas_print_ticket', 'nonce' ); |
| 106 |
if ( ! current_user_can( 'edit_ticket' ) ) { |
| 107 |
wp_send_json_error( array('message' => __('Unauthorized action. You do not have permission to get tickets for print.', 'awesome-support') ), 403); |
| 108 |
} |
| 109 |
$ids = isset( $_POST['ids'] ) ? array_map( 'sanitize_text_field', wp_unslash( (array) $_POST['ids'] ) ) : array(); |
| 110 |
|
| 111 |
foreach( $ids as $id ) { |
| 112 |
|
| 113 |
if ( ! empty( $ticket = wpas_get_ticket_by_id( $id ) ) ) { |
| 114 |
|
| 115 |
$replies = wpas_get_replies( $ticket->ID, 'any', [ |
| 116 |
'posts_per_page' => - 1, |
| 117 |
'orderby' => 'post_date', |
| 118 |
'order' => wpas_get_option( 'replies_order', 'ASC' ), |
| 119 |
'post_type' => apply_filters( 'wpas_replies_post_type', [ |
| 120 |
'ticket_history', |
| 121 |
'ticket_reply' |
| 122 |
] ), |
| 123 |
'post_parent' => $ticket->ID, |
| 124 |
'post_status' => apply_filters( 'wpas_replies_post_status', [ |
| 125 |
'publish', |
| 126 |
'inherit', |
| 127 |
'private', |
| 128 |
'trash', |
| 129 |
'read', |
| 130 |
'unread' |
| 131 |
] ) |
| 132 |
] ); |
| 133 |
|
| 134 |
include WPAS_PATH . 'includes/admin/views/print-ticket.php'; |
| 135 |
|
| 136 |
} else { |
| 137 |
|
| 138 |
esc_html_e( 'Ticket not found', 'awesome-support' ); |
| 139 |
|
| 140 |
} |
| 141 |
|
| 142 |
} |
| 143 |
|
| 144 |
wp_die(); |
| 145 |
|
| 146 |
} |
| 147 |
|
| 148 |
|
| 149 |
add_action( 'wp_ajax_wpas_close_ticket_prevent_client_notification', 'wpas_ajax_close_ticket_prevent_client_notification' ); |
| 150 |
/** |
| 151 |
* Handle request to set client notification flag about ticket close |
| 152 |
*/ |
| 153 |
function wpas_ajax_close_ticket_prevent_client_notification() { |
| 154 |
|
| 155 |
$prevent_client_notification = filter_input( INPUT_POST, 'prevent', FILTER_SANITIZE_NUMBER_INT ); |
| 156 |
$ticket_id = filter_input( INPUT_POST, 'ticket_id', FILTER_SANITIZE_NUMBER_INT ); |
| 157 |
|
| 158 |
|
| 159 |
if( !check_ajax_referer( 'prevent_client_notification', 'nonce', false ) || !current_user_can( 'edit_ticket' ) || !$ticket_id ) { |
| 160 |
wp_send_json_error( array( 'message' => "You don't have access to perform this action." ) ); |
| 161 |
die(); |
| 162 |
} |
| 163 |
|
| 164 |
update_post_meta( $ticket_id, 'wpas_close_ticket_prevent_client_notification', $prevent_client_notification ); |
| 165 |
|
| 166 |
wp_send_json_success(); |
| 167 |
} |
| 168 |
|