init_hooks(); } /** * Initialize hooks */ private function init_hooks() { // Add safety wrapper before MapGeo loads add_action('wp_enqueue_scripts', array($this, 'add_safety_wrapper'), 4); // Add error boundaries in footer add_action('wp_footer', array($this, 'add_error_boundaries'), 1); // Filter MapGeo shortcode output add_filter('do_shortcode_tag', array($this, 'wrap_mapgeo_shortcode'), 10, 4); } /** * Add safety wrapper script */ public function add_safety_wrapper() { // Only on find-a-trainer page if (!is_page() || get_post_field('post_name') !== 'find-a-trainer') { return; } wp_enqueue_script( 'hvac-mapgeo-safety', HVAC_PLUGIN_URL . 'assets/js/mapgeo-safety.js', array(), HVAC_PLUGIN_VERSION, false // Load in head to catch errors early ); // Add inline configuration wp_add_inline_script('hvac-mapgeo-safety', ' window.HVAC_MapGeo_Config = { maxRetries: 3, retryDelay: 2000, timeout: 10000, fallbackEnabled: true, debugMode: ' . (defined('WP_DEBUG') && WP_DEBUG ? 'true' : 'false') . ' }; ', 'before'); } /** * Add error boundaries in footer */ public function add_error_boundaries() { // Only on find-a-trainer page if (!is_page() || get_post_field('post_name') !== 'find-a-trainer') { return; } ?> '; $wrapped .= $output; $wrapped .= ''; // Add fallback content $wrapped .= ''; return $wrapped; } } // Initialize HVAC_MapGeo_Safety::get_instance();