| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
exit; // Exit if accessed directly |
| 4 |
} |
| 5 |
|
| 6 |
global $current_user; |
| 7 |
|
| 8 |
if ( |
| 9 |
check_ajax_referer('delete_status', '_ajax_nonce', false) != 1 |
| 10 |
) wp_send_json_error('Unauthorised request!', 400); |
| 11 |
|
| 12 |
if (!($current_user->ID && $current_user->has_cap('manage_options'))) {exit;} |
| 13 |
|
| 14 |
$status_id = isset($_POST) && isset($_POST['status_id']) ? intval($_POST['status_id']) : 0; |
| 15 |
if (!$status_id) {exit;} |
| 16 |
|
| 17 |
$wpsc_default_ticket_status = get_option('wpsc_default_ticket_status'); |
| 18 |
if ($wpsc_default_ticket_status == $status_id){ |
| 19 |
echo '{ "sucess_status":"0","messege":"'.__('Default ticket status can not be deleted.','supportcandy').'" }'; |
| 20 |
die(); |
| 21 |
} |
| 22 |
$wpsc_ticket_status_after_customer_reply = get_option('wpsc_ticket_status_after_customer_reply'); |
| 23 |
if ($wpsc_ticket_status_after_customer_reply == $status_id){ |
| 24 |
echo '{ "sucess_status":"0","messege":"'.__('Ticket status after customer reply can not be deleted.','supportcandy').'" }'; |
| 25 |
die(); |
| 26 |
} |
| 27 |
$wpsc_ticket_status_after_agent_reply = get_option('wpsc_ticket_status_after_agent_reply'); |
| 28 |
if ($wpsc_ticket_status_after_agent_reply == $status_id){ |
| 29 |
echo '{ "sucess_status":"0","messege":"'.__('Ticket status after agent reply can not be deleted.','supportcandy').'" }'; |
| 30 |
die(); |
| 31 |
} |
| 32 |
$wpsc_close_ticket_status = get_option('wpsc_close_ticket_status'); |
| 33 |
if ($wpsc_close_ticket_status == $status_id){ |
| 34 |
echo '{ "sucess_status":"0","messege":"'.__('Default ticket close status can not be deleted.','supportcandy').'" }'; |
| 35 |
die(); |
| 36 |
} |
| 37 |
|
| 38 |
$wpsc_custom_status_localize = get_option('wpsc_custom_status_localize'); |
| 39 |
unset($wpsc_custom_status_localize['custom_status_' .$status_id]); |
| 40 |
update_option('wpsc_custom_status_localize', $wpsc_custom_status_localize); |
| 41 |
|
| 42 |
wp_delete_term($status_id, 'wpsc_statuses'); |
| 43 |
|
| 44 |
do_action('wpsc_delete_status',$status_id); |
| 45 |
|
| 46 |
echo '{ "sucess_status":"1","messege":"'.__('Status deleted successfully.','supportcandy').'" }'; |
| 47 |
|