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' ); } public function meta_box_callback( $post ) { $image_id = intval( 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( $image_id, 'full' ) : ''; ?>
:
[advaimma_map id="ID ) ); ?>"]
post_type ) || 'advaimma_image_map' !== $post->post_type ) { return; } // Nonce verification. if ( empty( $_POST['advaimma_meta_nonce'] ) ) { return; } $nonce = sanitize_text_field( wp_unslash( $_POST['advaimma_meta_nonce'] ) ); if ( ! wp_verify_nonce( $nonce, 'advaimma_meta_nonce' ) ) { return; } // Autosave? if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { return; } // Capability. if ( ! current_user_can( 'edit_post', $post_id ) ) { return; } // Image ID. 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' ); } } // Spots sanitized at input level. $raw_spots = array(); if ( isset( $_POST['advaimma_spots'] ) && is_array( $_POST['advaimma_spots'] ) ) { $raw_spots = map_deep( wp_unslash( $_POST['advaimma_spots'] ), 'sanitize_text_field' ); } if ( ! is_array( $raw_spots ) ) { $raw_spots = array(); } $spots = array(); $allowed_triggers = array( 'hover', 'click' ); foreach ( $raw_spots as $s ) { if ( ! is_array( $s ) ) { continue; } $title = isset( $s['title'] ) ? sanitize_text_field( $s['title'] ) : ''; $content = isset( $s['content'] ) ? wp_kses_post( $s['content'] ) : ''; $icon = isset( $s['icon'] ) ? sanitize_text_field( $s['icon'] ) : ''; $icon_image = isset( $s['icon_image'] ) ? esc_url_raw( $s['icon_image'] ) : ''; $link = isset( $s['link'] ) ? esc_url_raw( $s['link'] ) : ''; $trigger = isset( $s['trigger'] ) ? sanitize_key( $s['trigger'] ) : 'hover'; $trigger = in_array( $trigger, $allowed_triggers, true ) ? $trigger : 'hover'; $x_raw = isset( $s['x'] ) ? $s['x'] : 50; $y_raw = isset( $s['y'] ) ? $s['y'] : 50; $x = round( min( 100, max( 0, floatval( $x_raw ) ) ), 4 ); $y = round( min( 100, max( 0, floatval( $y_raw ) ) ), 4 ); $spots[] = array( 'title' => $title, 'content' => $content, 'icon' => $icon, 'icon_image' => $icon_image, 'link' => $link, 'trigger' => $trigger, 'x' => $x, 'y' => $y, ); } update_post_meta( $post_id, 'advaimma_spots', $spots ); } }