register(); // Native integration with the active sitemap owner. self::registerActiveIntegration($service, $router, $renderer); // Keep the cached URL list fresh on content changes. foreach (['yatra_trip_created', 'yatra_trip_updated', 'yatra_trip_deleted'] as $hook) { add_action($hook, [SitemapService::class, 'flushCache']); } // ...and when the operator changes which types are published. Without // this the entry list is cached for an hour, so the setting would look // as though it had done nothing. foreach (['yatra_sitemap_types', 'yatra_enable_sitemap'] as $option) { add_action('update_option_' . $option, [SitemapService::class, 'flushCache']); add_action('add_option_' . $option, [SitemapService::class, 'flushCache']); add_action('delete_option_' . $option, [SitemapService::class, 'flushCache']); } } private static function registerActiveIntegration( SitemapService $service, SitemapRouter $router, SitemapRenderer $renderer ): void { if (defined('WPSEO_VERSION') || class_exists('WPSEO_Sitemaps')) { (new YoastIntegration($service, $router, $renderer))->register(); return; } if (defined('RANK_MATH_VERSION') || class_exists('RankMath\\Helper')) { (new RankMathIntegration($service, $router, $renderer))->register(); return; } if (defined('AIOSEO_VERSION') || function_exists('aioseo')) { (new AioseoIntegration($service, $router))->register(); return; } // No third-party SEO plugin: integrate with WordPress core sitemaps. $registerCore = static function () use ($service): void { if (!function_exists('wp_register_sitemap_provider')) { return; // Core sitemaps disabled or WP < 5.5. } if (function_exists('wp_sitemaps_get_server')) { wp_sitemaps_get_server(); // ensure base provider class is loaded } if (class_exists('WP_Sitemaps_Provider')) { wp_register_sitemap_provider('yatra', new CoreProvider($service)); } }; // Providers can boot before OR after `init` depending on the load path, // so register immediately when `init` already fired, otherwise hook it. if (did_action('init')) { $registerCore(); } else { add_action('init', $registerCore, 20); } } }