location_list(); ?>
__( 'Invalid security token or Insufficient permissions.', 'abp-event-ticket' ), 'type' => 'warn' ], 403 );
}
$term_id = isset( $_POST['id'] ) ? absint( wp_unslash( $_POST['id'] ) ) : '';
ob_start();
$name = $slug = $des = '';
$map_data = [];
$label = ABPET_Function::location_label();
$btn_label = __( 'Save', 'abp-event-ticket' ) . ' ' . $label;
$title = __( 'Add new ', 'abp-event-ticket' ) . ' ' . $label;
if ( ! empty( $term_id ) && $term_id > 0 ) {
$term = get_term( $term_id );
if ( ! empty( $term ) ) {
$name = $term->name;
$slug = $term->slug;
$des = $term->description;
$btn_label = __( 'Update', 'abp-event-ticket' ) . ' ' . $label . ' ' . $name;
$title = __( 'Edit ', 'abp-event-ticket' ) . ' ' . $label . ' ' . $name;
$map_data = get_term_meta( $term_id, '_abpet_map', true );
$map_data = is_array( $map_data ) ? $map_data : [];
}
}
$google_map_key = ABPET_Function::get_options( 'abpet_configuration', 'google_map_key', '' );
$show_map = ABPET_Function::on_off( 'google_map' ) && ! empty( $google_map_key );
?>
$html, 'type' => 'success', 'msg' => $label . ' ' . __( 'Form Loaded Successfully .....! ', 'abp-event-ticket' ) ] );
}
public function save_tax_location(): void {
if ( ! check_ajax_referer( 'abpet_admin_ajax_nonce', 'nonce', false ) || ! current_user_can( 'manage_options' ) ) {
wp_send_json_error( [ 'msg' => __( 'Invalid security token or Insufficient permissions.', 'abp-event-ticket' ), '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;
$tax_id = $post_int( 'id' );
$name = $post_val( 'name' );
$slug = $post_slug( 'slug' );
$description = $post_val( 'description' );
$post_id = $post_int( 'post_id' );
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' => ABPET_Function::location_label() . ' ' . __( 'Name cannot be blank!', 'abp-event-ticket' ), 'type' => 'warn' ] );
}
if ( $tax_id > 0 ) {
$result = wp_update_term( $tax_id, 'abpet_location', [
'name' => $name,
'slug' => $slug,
'description' => $description,
] );
} else {
$result = wp_insert_term( $name, 'abpet_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-event-ticket' ), 'type' => 'warn' ] );
}
$map_lat = $post_val( 'map_lat' );
$map_lng = $post_val( 'map_lng' );
$map_place = $post_val( 'map_place' );
$map_address = $post_val( 'map_address' );
if ( ABPET_Function::on_off( 'google_map' ) && ! empty( $map_lat ) && ! empty( $map_lng ) ) {
update_term_meta( $term_id, '_abpet_map', [
'lat' => $map_lat,
'lng' => $map_lng,
'place' => $map_place,
'address' => $map_address,
] );
} else {
delete_term_meta( $term_id, '_abpet_map' );
}
$this->update_location();
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' => ABPET_Function::location_label() . ' ' . __( 'Saved Successfully !', 'abp-event-ticket' ),
'js' => ABPET_Function::option_js($post_id,'abpet_location'),
] );
}
public function delete_tax_location(): void {
if ( ! check_ajax_referer( 'abpet_admin_ajax_nonce', 'nonce', false ) || ! current_user_can( 'manage_options' ) ) {
wp_send_json_error( [ 'msg' => __( 'Invalid security token or Insufficient permissions.', 'abp-event-ticket' ), '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' => ABPET_Function::location_label() . ' ' . __( 'id Invalid...!', 'abp-event-ticket' ), 'type' => 'warn' ] );
}
$result = wp_delete_term( $tax_id, 'abpet_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' => ABPET_Function::location_label() . ' ' . __( 'Deleted Successfully !', 'abp-event-ticket' ) ] );
}
public function update_location(): void {
$taxonomies = ABPET_Function::get_taxonomy( 'abpet_location' );
$taxonomies = is_array( $taxonomies ) ? $taxonomies : [];
$location = [];
if ( count( $taxonomies ) > 0 ) {
foreach ( $taxonomies as $taxonomy ) {
$term_id = $taxonomy->term_id;
$location[ $term_id ]['label'] = $taxonomy->name;
$location[ $term_id ]['description'] = $taxonomy->description;
$location[ $term_id ]['slug'] = $taxonomy->slug;
$map = get_term_meta( $term_id, '_abpet_map', true );
if ( is_array( $map ) && ! empty( $map ) ) {
$location[ $term_id ]['map'] = $map;
}
}
}
ksort( $location );
update_option( 'abpet_location', $location );
}
public function location_list(): void {
$options = ABPET_Function::get_option( 'abpet_location' );
$options = is_array( $options ) ? $options : [];
$count = 1;
if ( count( $options ) > 0 ) { ?>
|
|
|
|
|
|
$option ) {
$name = $option['label'] ?? $option['name'] ?? ''; ?>
| . |
|
|
|
[abpet-post loc_id=""] |
|