location_list(); ?>
__('Invalid security token or Insufficient permissions.', 'abp-transport-booking'), 'type' => 'warn'], 403); } $term_id = isset($_POST['id']) ? absint(wp_unslash($_POST['id'])) : 0; ob_start(); $name = $slug = $des = ''; $label = ABPTB_Function::location_label(); $btn_label = __('Save', 'abp-transport-booking') . ' ' . $label; $title = __('Add new ', 'abp-transport-booking') . ' ' . $label; $location = []; if (!empty($term_id)) { $term = get_term($term_id); if (!empty($term)) { $locations = ABPTB_Function::get_option('abptb_location'); $locations = is_array($locations) ? $locations : []; $location = $locations[$term_id] ?? []; $name = $term->name; $slug = $term->slug; $des = $term->description; $btn_label = __('Update', 'abp-transport-booking') . ' ' . $label . ' ' . $name; $title = __('Edit ', 'abp-transport-booking') . ' ' . $label . ' ' . $name; } } $pick_infos = $location['pd_info'] ?? []; ?>
📍
$pick_info) { self::pickup_form($pick_info, $key); } } ?>
$html, 'type' => 'success', 'msg' => $label . ' ' . __('Form Loaded Successfully .....! ', 'abp-transport-booking')]); } public function save_tax_location(): void { if (!check_ajax_referer('abptb_admin_ajax_nonce', 'nonce', false) || !current_user_can('manage_options')) { wp_send_json_error(['msg' => __('Invalid security token or Insufficient permissions.', 'abp-transport-booking'), 'type' => 'warn'], 403); } $post_int = fn($key, $default = 0) => isset($_POST[$key]) ? absint($_POST[$key]) : $default; $post_val = fn($key, $default = '') => isset($_POST[$key]) ? sanitize_text_field(wp_unslash($_POST[$key])) : $default; $post_slug = fn($key, $default = '') => isset($_POST[$key]) ? sanitize_title(wp_unslash($_POST[$key])) : $default; $post_array = fn($key) => (isset($_POST[$key]) && is_array($_POST[$key])) ? array_map('sanitize_text_field', wp_unslash($_POST[$key])) : []; $tax_id = $post_int('id'); $name = $post_val('name'); $slug = $post_slug('slug'); $description = $post_val('description'); $post_id = $post_int('post_id'); $pick_ids = $post_array('pick_id'); $pick_names = $post_array('pick_name'); $pick_times = $post_array('pick_time'); if (empty($name)) { ob_start(); $html = ''; if (empty($post_id) || $post_id <= 0) { ob_start(); $this->location_list(); $html = ob_get_clean(); } wp_send_json_error(['html' => $html, 'msg' => ABPTB_Function::location_label() . ' ' . __('Name cannot be blank!', 'abp-transport-booking'), 'type' => 'warn']); } if ($tax_id > 0) { $result = wp_update_term($tax_id, 'abptb_location', [ 'name' => $name, 'slug' => $slug, 'description' => $description, ]); } else { $result = wp_insert_term($name, 'abptb_location', [ 'slug' => $slug, 'description' => $description, ]); } if (is_wp_error($result)) { wp_send_json_error(['html' => '', 'msg' => $result->get_error_message()]); } $term_id = absint($result['term_id'] ?? 0); if ($term_id <= 0) { wp_send_json_error(['html' => '', 'msg' => __('Failed to resolve location context.', 'abp-transport-booking'), 'type' => 'warn']); } $pickup_info = []; if (!empty($pick_names)) { foreach ($pick_names as $key => $pick) { if (!empty($pick)) { $pick_id = isset($pick_ids[$key]) && $pick_ids[$key] !== '' ? $pick_ids[$key] : uniqid(); $pickup_info[$pick_id]['name'] = $pick; $pickup_info[$pick_id]['time'] = $pick_times[$key] ?? ''; } } } $this->update_location($pickup_info, $term_id); ob_start(); $html = ''; if (empty($post_id) || $post_id <= 0) { ob_start(); $this->location_list(); $html = ob_get_clean(); } wp_send_json_success([ 'html' => $html, 'type' => 'success', 'msg' => ABPTB_Function::location_label() . ' ' . __('Saved Successfully !', 'abp-transport-booking'), 'js' => (!empty($post_id) && $post_id > 0 ? ABPTB_Function::location_info_js() : ''), ]); } public function delete_tax_location(): void { if (!check_ajax_referer('abptb_admin_ajax_nonce', 'nonce', false) || !current_user_can('manage_options')) { wp_send_json_error(['msg' => __('Invalid security token or Insufficient permissions.', 'abp-transport-booking'), 'type' => 'warn'], 403); } $tax_id = isset($_POST['id']) ? absint(wp_unslash($_POST['id'])) : ''; if (empty($tax_id) || !is_numeric($tax_id)) { ob_start(); $this->location_list(); $html = ob_get_clean(); wp_send_json_error(['html' => $html, 'msg' => ABPTB_Function::location_label() . ' ' . __('id Invalid...!', 'abp-transport-booking'), 'type' => 'warn']); } $result = wp_delete_term($tax_id, 'abptb_location'); $this->update_location(); ob_start(); $this->location_list(); $html = ob_get_clean(); if (is_wp_error($result)) { wp_send_json_error(['html' => $html, 'msg' => $result->get_error_message(), 'type' => 'warn']); } wp_send_json_success(['html' => $html, 'type' => 'success', 'msg' => ABPTB_Function::location_label() . ' ' . __('Deleted Successfully !', 'abp-transport-booking')]); } public function update_location($pickup_info = [], $id = ''): void { $taxonomies = ABPTB_Function::get_taxonomy('abptb_location'); $taxonomies = is_array($taxonomies) ? $taxonomies : []; $location = []; $old_location = ABPTB_Function::get_option('abptb_location'); $pd_option = []; $old_location = is_array($old_location) ? $old_location : []; if (count($taxonomies) > 0) { foreach ($taxonomies as $taxonomy) { $term_id = $taxonomy->term_id; $location[$term_id]['name'] = $taxonomy->name; $location[$term_id]['description'] = $taxonomy->description; $location[$term_id]['slug'] = $taxonomy->slug; $pd_option[$term_id] = $taxonomy->name; if (!empty($id) && (int)$id === (int)$term_id) { $new_location = $pickup_info; $pd_info = $pickup_info; } else { $pd_info = $old_location[$term_id]['pd_info'] ?? []; if (!empty($pd_info)) { $new_location = $old_location[$term_id]['pd_info'] ?? []; } } if (!empty($pd_info)) { foreach ($pd_info as $pd_info_key => $pd_info_value) { $pd_option[$pd_info_key] = $pd_info_value['name'] ?? ''; } } if (!empty($new_location)) { $location[$term_id]['pd_info'] = $new_location; } } } ksort($location); update_option('abptb_location', $location); update_option('abptb_pd', $pd_option); } public function location_list(): void { $options = ABPTB_Function::get_option('abptb_location'); $options = is_array($options) ? $options : []; $count = 1; if (count($options) > 0) { ?> $option) { $name = $option['name'] ?? ''; ?>
.
[abptb-post loc_id=""]