Skip to content

Commit d2582a4

Browse files
v7.9-a24: * **3rd** Cache purge compatibility w/ RankMath SEO (Ryan D, PR#977)
Update rank-math.cls.php
1 parent 8436765 commit d2582a4

2 files changed

Lines changed: 54 additions & 0 deletions

File tree

thirdparty/entry.inc.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,4 @@
5252
add_action('litespeed_init', 'LiteSpeed\Thirdparty\Elementor::preload');
5353
add_action('litespeed_init', 'LiteSpeed\Thirdparty\Gravity_Forms::preload');
5454
add_action('litespeed_init', 'LiteSpeed\Thirdparty\Perfmatters::preload');
55+
add_action('litespeed_init', 'LiteSpeed\Thirdparty\Rank_Math::preload');

thirdparty/rank-math.cls.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
/**
3+
* The Third Party integration with the Rank Math SEO plugin.
4+
*
5+
* @since 7.9
6+
* @package LiteSpeed
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+
* Preload hooks for Rank Math integration.
27+
*
28+
* @since 7.9
29+
* @access public
30+
* @return void
31+
*/
32+
public static function preload() {
33+
if ( ! defined( 'RANK_MATH_VERSION' ) ) {
34+
return;
35+
}
36+
add_action('litespeed_purged_post', __CLASS__ . '::invalidate_sitemap_cache');
37+
// add_action('litespeed_purged_all', __CLASS__ . '::invalidate_sitemap_cache');
38+
}
39+
40+
/**
41+
* Invalidates Rank Math's sitemap cache.
42+
*
43+
* @since 7.9
44+
* @return void
45+
*/
46+
public static function invalidate_sitemap_cache() {
47+
if (class_exists('\\RankMath\\Sitemap\\Cache')) {
48+
\RankMath\Sitemap\Cache::invalidate_storage();
49+
50+
do_action( 'litespeed_debug', '[3rd] Rank Math sitemap cache invalidated' );
51+
}
52+
}
53+
}

0 commit comments

Comments
 (0)