| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
exit; // Exit if accessed directly |
| 4 |
} |
| 5 |
|
| 6 |
global $current_user, $wpdb; |
| 7 |
|
| 8 |
if ( |
| 9 |
check_ajax_referer('set_add_category', '_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 |
$cat_name = isset($_POST) && isset($_POST['cat_name']) ? sanitize_text_field($_POST['cat_name']) : ''; |
| 15 |
if (!$cat_name) {exit;} |
| 16 |
|
| 17 |
$flag = 0; |
| 18 |
|
| 19 |
$term = wp_insert_term( $cat_name, 'wpsc_categories' ); |
| 20 |
if (!is_wp_error($term) && isset($term['term_id'])) { |
| 21 |
$load_order = $wpdb->get_var("select max(meta_value) as load_order from {$wpdb->prefix}termmeta WHERE meta_key='wpsc_category_load_order'"); |
| 22 |
add_term_meta ($term['term_id'], 'wpsc_category_load_order', ++$load_order); |
| 23 |
|
| 24 |
$wpsc_custom_category_localize = get_option('wpsc_custom_category_localize'); |
| 25 |
if(!$wpsc_custom_category_localize){ |
| 26 |
$wpsc_custom_category_localize = array(); |
| 27 |
} |
| 28 |
$wpsc_custom_category_localize['custom_category_'.$term['term_id']] = stripslashes($cat_name); |
| 29 |
update_option('wpsc_custom_category_localize', $wpsc_custom_category_localize); |
| 30 |
|
| 31 |
do_action('wpsc_set_add_category',$term['term_id']); |
| 32 |
echo '{ "sucess_status":"1","messege":"'.__('Category added successfully.','supportcandy').'" }'; |
| 33 |
} else { |
| 34 |
echo '{ "sucess_status":"0","messege":"'.__('An error occured while creating category.','supportcandy').'" }'; |
| 35 |
} |
| 36 |
|