assets_enqueued) { return; } wp_enqueue_style( 'mximap-public', MXIMAP_PLUGIN_URL . 'public/css/mximap-public.css', array(), MXIMAP_VERSION ); wp_enqueue_script( 'mximap-public', MXIMAP_PLUGIN_URL . 'public/js/mximap-public.js', array(), MXIMAP_VERSION, true ); $this->assets_enqueued = true; } /** * Keep a late/fragment render styled after the normal asset output has run. * Return markup with the shortcode so fragment/cache consumers retain it. */ private function render_late_assets() { if (!did_action('wp_print_footer_scripts') && !wp_doing_ajax()) { return ''; } ob_start(); if (!wp_style_is('mximap-public', 'done')) { wp_print_styles(array('mximap-public')); } if (!wp_script_is('mximap-public', 'done')) { wp_print_scripts(array('mximap-public')); } return ob_get_clean(); } /** * Render the shortcode */ public function render_shortcode($atts) { $atts = shortcode_atts(array( 'id' => 0, ), $atts, 'mximap_map'); $map_id = absint($atts['id']); // Validate map exists if (!$map_id) { return $this->render_error(__('No map ID specified.', 'max-interactive-maps')); } $map_post = get_post($map_id); if (!$map_post || MXIMAP_Post_Type::POST_TYPE !== $map_post->post_type) { return $this->render_error(__('Map not found.', 'max-interactive-maps')); } if ('publish' !== $map_post->post_status) { return $this->render_error(__('This map is not published.', 'max-interactive-maps')); } // Keep the first legacy ID; suffix only later valid renders of this map. $render_count = ($this->map_render_counts[$map_id] ?? 0) + 1; $this->map_render_counts[$map_id] = $render_count; $map_dom_id = 'mximap-map-' . $map_id; if ($render_count > 1) { $map_dom_id .= '-instance-' . $render_count; } // Enqueue assets $this->enqueue_assets(); $late_assets = $this->render_late_assets(); // Get map data $pins = get_post_meta($map_id, '_mximap_pins', true); $pins = MXIMAP_Post_Type::readable_pins($pins); $settings = get_post_meta($map_id, '_mximap_settings', true); $settings = MXIMAP_Post_Type::resolve_settings($settings); $map_title = wp_strip_all_tags(get_the_title($map_post)); /* translators: %s: map title. */ $map_label = $map_title ? sprintf(__('Interactive map: %s', 'max-interactive-maps'), $map_title) : __('Interactive map', 'max-interactive-maps'); // Build output ob_start(); ?>