wp_create_nonce( 'advaimma_save' ),
'strings' => array(
'addPoint' => esc_html__( 'Add Point', 'advance-image-mapping' ),
'remove' => esc_html__( 'Remove', 'advance-image-mapping' ),
),
)
);
}
public function register_meta_boxes() {
add_meta_box(
'advaimma_meta',
esc_html__( 'Hotspot Builder', 'advance-image-mapping' ),
array( $this, 'meta_box_callback' ),
'advaimma_image_map',
'normal',
'high'
);
add_meta_box(
'advaimma_design_meta',
esc_html__( 'Design Settings', 'advance-image-mapping' ),
array( $this, 'design_meta_box_callback' ),
'advaimma_image_map',
'side',
'default'
);
}
public function meta_box_callback( $post ) {
$image_id = get_post_meta( $post->ID, 'advaimma_image_id', true );
$spots = get_post_meta( $post->ID, 'advaimma_spots', true );
if ( ! is_array( $spots ) ) {
$spots = array();
}
wp_nonce_field( 'advaimma_meta_nonce', 'advaimma_meta_nonce' );
$image_url = $image_id ? wp_get_attachment_image_url( intval( $image_id ), 'full' ) : '';
?>
$s ) :
$x = isset( $s['x'] ) ? floatval( $s['x'] ) : 50;
$y = isset( $s['y'] ) ? floatval( $s['y'] ) : 50;
$icon_image = isset( $s['icon_image'] ) ? esc_url( $s['icon_image'] ) : '';
?>
'#ffffff',
'content_color' => '#ffffff',
'tip_bg_color' => '#333333',
'point_bg_color' => '#000000',
'number_color' => '#ffffff',
);
$colors = wp_parse_args( get_post_meta( $post->ID, 'advaimma_colors', true ), $defaults );
wp_nonce_field( 'advaimma_design_nonce', 'advaimma_design_nonce' );
?>
post_type ) || 'advaimma_image_map' !== $post->post_type ) {
return;
}
if ( ! empty( $_POST['advaimma_colors'] ) && isset( $_POST['advaimma_design_nonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['advaimma_design_nonce'] ) ), 'advaimma_design_nonce' ) ) {
$colors = array_map( 'sanitize_hex_color', wp_unslash( $_POST['advaimma_colors'] ) );
update_post_meta( $post_id, 'advaimma_colors', $colors );
}
// Save existing hotspot data (no change)
if ( empty( $_POST['advaimma_meta_nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['advaimma_meta_nonce'] ) ), 'advaimma_meta_nonce' ) ) {
return;
}
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return;
}
if ( ! current_user_can( 'edit_post', $post_id ) ) {
return;
}
if ( isset( $_POST['advaimma_image_id'] ) ) {
$image_id = intval( wp_unslash( $_POST['advaimma_image_id'] ) );
if ( $image_id > 0 ) {
update_post_meta( $post_id, 'advaimma_image_id', $image_id );
} else {
delete_post_meta( $post_id, 'advaimma_image_id' );
}
}
$raw_spots = isset( $_POST['advaimma_spots'] ) ? wp_unslash( $_POST['advaimma_spots'] ) : array();
if ( ! is_array( $raw_spots ) ) {
return;
}
$spots = array();
foreach ( $raw_spots as $s ) {
if ( empty( $s['title'] ) && empty( $s['content'] ) ) {
continue;
}
$spots[] = array(
'title' => sanitize_text_field( $s['title'] ),
'content' => wp_kses_post( $s['content'] ),
'icon' => sanitize_text_field( $s['icon'] ),
'icon_image' => esc_url_raw( $s['icon_image'] ),
'trigger' => in_array( $s['trigger'], array( 'hover', 'click' ), true ) ? $s['trigger'] : 'hover',
'x' => floatval( $s['x'] ),
'y' => floatval( $s['y'] ),
);
}
update_post_meta( $post_id, 'advaimma_spots', $spots );
}
}