location_list(); ?>
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; $location[$term_id]['lat'] = get_term_meta((int)$term_id, 'abprf_loc_lat', true); $location[$term_id]['lng'] = get_term_meta((int)$term_id, 'abprf_loc_lng', true); $location[$term_id]['radius'] = get_term_meta((int)$term_id, 'abprf_loc_radius', true); $polygon = get_term_meta((int)$term_id, 'abprf_loc_polygon', true); $location[$term_id]['polygon'] = is_array($polygon) ? $polygon : []; } } ksort($location); update_option('abprf_location', $location); } public function location_list(): void { $all_locations = ABPRF_Function::get_option('abprf_location'); $all_locations = is_array($all_locations) ? $all_locations : []; $count = 1; if (count($all_locations) > 0) { ?> $location) { $name = $location['name'] ?? ''; $description = $location['description'] ?? ''; $lat = $location['lat'] ?? ''; $lng = $location['lng'] ?? ''; $radius = $location['radius'] ?? ''; $has_geo = $lat !== '' || $lng !== '' || $radius !== '' || !empty($location['polygon']); ?>
. 📍
[abprf-post loc_id=""] [abprf-property loc_id=""]
0) { ?>
$location) { $name = $location['name'] ?? ''; ?>

'', 'msg' => __('Invalid security token.', 'abp-rentalforge')], 403); } if (!current_user_can('manage_options')) { wp_send_json_error(['html' => '', 'msg' => __('Insufficient permissions.', 'abp-rentalforge')], 403); } $loc_id = isset($_POST['tax_id']) ? sanitize_text_field(wp_unslash($_POST['tax_id'])) : ''; $locations = ABPRF_Function::get_option('abprf_location'); $locations = is_array($locations) ? $locations : []; $location = $locations[$loc_id] ?? []; ob_start(); $this->form($location, $loc_id); $html = ob_get_clean(); wp_send_json_success(['html' => $html, 'msg' => __('Location Form Loaded Successfully .....! ', 'abp-rentalforge')]); } public function save_location(): void { if (!check_ajax_referer('abprf_admin_ajax_nonce', 'nonce', false)) { wp_send_json_error(['html' => '', 'msg' => __('Invalid security token.', 'abp-rentalforge')], 403); } if (!current_user_can('manage_options')) { wp_send_json_error(['html' => '', 'msg' => __('Insufficient permissions.', 'abp-rentalforge')], 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; $cat_term_id = $post_int('loc_term_id'); $name = $post_val('name'); $slug = $post_slug('slug'); $description = $post_val('description'); $lat = $post_val('lat'); $lng = $post_val('lng'); $radius = $post_val('radius'); $polygon = []; if (isset($_POST['polygon'])) { $polygon_lines = preg_split('/\r\n|\r|\n/', sanitize_textarea_field(wp_unslash($_POST['polygon']))); if (is_array($polygon_lines)) { foreach ($polygon_lines as $line) { $line = trim($line); if ($line === '') { continue; } $parts = array_map('trim', explode(',', $line)); if (count($parts) >= 2 && is_numeric($parts[0]) && is_numeric($parts[1])) { $polygon[] = ['lat' => (float)$parts[0], 'lng' => (float)$parts[1]]; } } } } $abprf_post_id = $post_int('abprf_post_id'); if (empty($name)) { wp_send_json_error(['html' => '', 'msg' => __('Location Name cannot be blank!', 'abp-rentalforge')]); } if ($cat_term_id > 0) { $result = wp_update_term($cat_term_id, 'abprf_location', [ 'name' => $name, 'slug' => $slug, 'description' => $description, ]); } else { $result = wp_insert_term($name, 'abprf_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-rentalforge')]); } update_term_meta((int)$term_id, 'abprf_loc_lat', sanitize_text_field($lat)); update_term_meta((int)$term_id, 'abprf_loc_lng', sanitize_text_field($lng)); update_term_meta((int)$term_id, 'abprf_loc_radius', sanitize_text_field($radius)); update_term_meta((int)$term_id, 'abprf_loc_polygon', $polygon); $this->update_location(); $msg = __('Location Saved Successfully !', 'abp-rentalforge'); ob_start(); if ($abprf_post_id > 0) { $_location = ABPRF_Function::get_post_info($abprf_post_id, 'abprf_location'); self::location_selection($_location); } else { $this->location_list(); } $html = ob_get_clean(); wp_send_json_success(['html' => $html, 'msg' => $msg]); } public function delete_location(): void { if (!check_ajax_referer('abprf_admin_ajax_nonce', 'nonce', false)) { wp_send_json_error(['html' => '', 'msg' => __('Invalid security token.', 'abp-rentalforge')], 403); } if (!current_user_can('manage_options')) { wp_send_json_error(['html' => '', 'msg' => __('Insufficient permissions.', 'abp-rentalforge')], 403); } $loc_id = isset($_POST['loc_id']) ? sanitize_text_field(wp_unslash($_POST['loc_id'])) : ''; $result = wp_delete_term((int)$loc_id, 'abprf_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()]); } global $wpdb; $table_name = $wpdb->prefix . 'abprf_property'; $all_ids = ABPRF_Query::get_post_id(['loc_id' => $loc_id]); if (count($all_ids) > 0) { foreach ($all_ids as $id) { $location = ABPRF_Function::get_post_info($id, 'location'); $location_array = !empty($location) ? explode(',', $location) : []; if (in_array($loc_id, $location_array, true)) { $location_array = array_diff($location_array, [$loc_id]); $updated_location = !empty($location_array) ? implode(',', $location_array) : ''; update_post_meta($id, 'location', $updated_location); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching $wpdb->update( $table_name, ['location' => $updated_location], ['post_id' => (int)$id], ['%s'], ['%d'] ); } } } wp_send_json_success(['html' => $html, 'msg' => __('Location Deleted Successfully !', 'abp-rentalforge')]); } } new ABPRF_Location(); }