|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * The Third Party integration with the Rank Math SEO plugin. |
| 4 | + * |
| 5 | + * @since 7.9 |
| 6 | + * @package Lit |
| 7 | + * @subpackage LiteSpeed_Cache/thirdparty |
| 8 | + */ |
| 9 | + |
| 10 | +namespace LiteSpeed\Thirdparty; |
| 11 | + |
| 12 | +defined('WPINC') || exit(); |
| 13 | + |
| 14 | +/** |
| 15 | + * Provides compatibility for the Rank Math SEO plugin. |
| 16 | + * |
| 17 | + * Rank Math maintains its own internal sitemap cache that can |
| 18 | + * occasionally fail to update when posts/pages are modified via |
| 19 | + * programmatic flows (page builders, duplicator plugins, etc.). |
| 20 | + * Tying its sitemap cache invalidation to LiteSpeed's "Purge All" |
| 21 | + * gives users a reliable way to force a refresh. |
| 22 | + */ |
| 23 | +class Rank_Math { |
| 24 | + |
| 25 | + /** |
| 26 | + * Detects if Rank Math is active. |
| 27 | + * |
| 28 | + * @since 7.9 |
| 29 | + * @return void |
| 30 | + */ |
| 31 | + public static function detect() { |
| 32 | + if ( ! defined( 'RANK_MATH_VERSION' ) ) { |
| 33 | + return; |
| 34 | + } |
| 35 | + } |
| 36 | + |
| 37 | + /** |
| 38 | + * Preload hooks for Rank Math integration. |
| 39 | + * |
| 40 | + * @since 7.9 |
| 41 | + * @access public |
| 42 | + * @return void |
| 43 | + */ |
| 44 | + public static function preload() { |
| 45 | + if ( ! defined( 'RANK_MATH_VERSION' ) ) { |
| 46 | + return; |
| 47 | + } |
| 48 | + add_action('litespeed_purged_post', __CLASS__ . '::invalidate_sitemap_cache'); |
| 49 | + // add_action('litespeed_purged_all', __CLASS__ . '::invalidate_sitemap_cache'); |
| 50 | + } |
| 51 | + |
| 52 | + /** |
| 53 | + * Invalidates Rank Math's sitemap cache. |
| 54 | + * |
| 55 | + * @since 7.9 |
| 56 | + * @return void |
| 57 | + */ |
| 58 | + public static function invalidate_sitemap_cache() { |
| 59 | + if (class_exists('\\RankMath\\Sitemap\\Cache')) { |
| 60 | + \RankMath\Sitemap\Cache::invalidate_storage(); |
| 61 | + |
| 62 | + do_action( 'litespeed_debug', '[3rd] Rank Math sitemap cache invalidated' ); |
| 63 | + } |
| 64 | + } |
| 65 | +} |
0 commit comments