# supportcandy/2.3.1/includes/admin/custom_fields/delete_custom_field.php

SupportCandy – AI Customer Support Ticket System &amp; Live Chatbot Agent, version 2.3.1. 34 lines.

- Page: https://pluginprobe.com/plugins/supportcandy/2.3.1/code/includes/admin/custom_fields/delete_custom_field.php
- Raw: https://pluginprobe.com/plugins/supportcandy/2.3.1/raw/includes/admin/custom_fields/delete_custom_field.php
- Modified: 2022-07-21T08:20:56+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/supportcandy/2.3.1/code/includes/admin/custom_fields/delete_custom_field.php#L10-L20`.

```php
<?php
if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly
}

if (
	check_ajax_referer('delete_custom_field', '_ajax_nonce', false) != 1
) wp_send_json_error('Unauthorised request!', 400);

global $current_user;
if (!($current_user->ID && $current_user->has_cap('manage_options'))) {exit;}

$field_id = isset($_POST) && isset($_POST['field_id']) ? intval($_POST['field_id']) : 0;
if (!$field_id) {exit;}

$wpsc_tf_type = get_term_meta( $field_id, 'wpsc_tf_type', true);

if ($wpsc_tf_type!='0') {
	$custom_fields_localize = get_option('wpsc_custom_fields_localize');
  unset($custom_fields_localize['custom_fields_' .$field_id]);
  update_option('wpsc_custom_fields_localize', $custom_fields_localize);
	
	$custom_fields_extra_info = get_option('wpsc_custom_fields_extra_info');
	unset($custom_fields_extra_info['custom_fields_extra_info_' .$field_id]);
	update_option('wpsc_custom_fields_extra_info', $custom_fields_extra_info);
	
	do_action('wpsc_delete_custom_field',$field_id);
	wp_delete_term($field_id, 'wpsc_ticket_custom_fields');
	
	echo '{ "sucess_status":"1","messege":"'.__('Field deleted successfully.','supportcandy').'" }';
} else {
	echo '{ "sucess_status":"0","messege":"'.__('Default field can not be deleted.','supportcandy').'" }';
}

```
