PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 4.7.0
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v4.7.0
4.7.0 4.6.1 4.6.0 4.5.5 4.5.4 4.5.3 4.5.2 3.2.20 3.2.21 3.2.22 3.2.3 3.2.5 3.2.6 3.2.7 3.2.9 3.3.0 3.3.1 3.3.2 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.7.0 3.7.1 All 111 releases
← All changes | compatibility/class-wpo-polylang-compatibility.php +38 -34 3.2.20 → 4.7.0 View file →
@@ -13,21 +13,15 @@
13 13 *
14 14 * @var WPO_Polylang_Compatibility|null
15 15 */
16 16 protected static $instance = null;
17 -
17 +
18 18 /**
19 19 * Constructor.
20 20 */
21 21 private function __construct() {
22 - // Check if polylang is active
23 - if (!class_exists('Polylang')) {
24 - return;
25 - }
26 -
27 - // Add action hooks to delete cache for all languages
28 - add_action('wpo_single_post_cache_deleted', array($this, 'polylang_delete_post_cache_for_all_languages'));
29 - add_action('wpo_single_post_feed_cache_deleted', array($this, 'polylang_delete_post_feed_cache_for_all_languages'));
22 + add_action('wpo_single_post_cache_deleted', array($this, 'delete_post_cache_for_all_languages'));
23 + add_action('wpo_single_post_feed_cache_deleted', array($this, 'delete_post_feed_cache_for_all_languages'));
30 24 }
31 25
32 26 /**
33 27 * Returns singleton instance.
@@ -34,10 +28,10 @@
34 28 *
35 29 * @return WPO_Polylang_Compatibility
36 30 */
37 31 public static function instance() {
38 - if (null == self::$instance) {
39 - self::$instance = new self;
32 + if (null === self::$instance) {
33 + self::$instance = new self();
40 34 }
41 35
42 36 return self::$instance;
43 37 }
@@ -42,26 +36,40 @@
42 36 return self::$instance;
43 37 }
44 38
45 39 /**
40 + * Gets translated post IDs excluding the original post.
41 + *
42 + * @param int $post_id The original post ID.
43 + * @return array<string, int> List of translated post IDs, excluding the original.
44 + */
45 + private function get_related_translations($post_id) {
46 + if (!function_exists('pll_get_post_translations')) {
47 + return array();
48 + }
49 +
50 + $translations = pll_get_post_translations($post_id);
51 +
52 + return array_filter($translations, function ($id) use ($post_id) {
53 + return $id !== $post_id;
54 + });
55 + }
56 +
57 + /**
46 58 * Deletes cache files for all connected languages for a post.
47 59 *
48 60 * @param int $deleted_post_id Post id whose cache file is already deleted.
61 + * @return void
49 62 */
50 - public function polylang_delete_post_cache_for_all_languages($deleted_post_id) {
63 + public function delete_post_cache_for_all_languages($deleted_post_id) {
64 + $related_ids = $this->get_related_translations($deleted_post_id);
51 65
52 - // Check if polylang translation function is available
53 - if (!function_exists('pll_get_post_translations')) {
54 - return;
66 + foreach ($related_ids as $post_id) {
67 + WPO_Page_Cache::really_delete_single_post_cache($post_id);
55 68 }
56 69
57 - $translated_post_ids = pll_get_post_translations($deleted_post_id);
58 -
59 - // Delete cache for each translated post
60 - foreach ($translated_post_ids as $post_id) {
61 - if ($deleted_post_id !== $post_id) {
62 - WPO_Page_Cache::really_delete_single_post_cache($post_id);
63 - }
70 + if (!empty($related_ids)) {
71 + WPO_Page_Cache::instance()->file_log("Cache for associated Polylang translation posts for Title: {{title}} have been purged", $deleted_post_id);
64 72 }
65 73 }
66 74
67 75 /**
@@ -67,22 +75,18 @@
67 75 /**
68 76 * Deletes cache files for all connected languages for a post feed.
69 77 *
70 78 * @param int $deleted_post_id Post id whose cache file for feed is already deleted.
79 + * @return void
71 80 */
72 - public function polylang_delete_post_feed_cache_for_all_languages($deleted_post_id) {
73 -
74 - // Check if polylang translation function is available
75 - if (!function_exists('pll_get_post_translations')) {
76 - return;
81 + public function delete_post_feed_cache_for_all_languages($deleted_post_id) {
82 + $related_ids = $this->get_related_translations($deleted_post_id);
83 +
84 + foreach ($related_ids as $post_id) {
85 + WPO_Page_Cache::really_delete_post_feed_cache($post_id);
77 86 }
78 87
79 - $translated_post_ids = pll_get_post_translations($deleted_post_id);
80 -
81 - // Delete cache for each translated post
82 - foreach ($translated_post_ids as $post_id) {
83 - if ($deleted_post_id !== $post_id) {
84 - WPO_Page_Cache::really_delete_post_feed_cache($post_id);
85 - }
88 + if (!empty($related_ids)) {
89 + WPO_Page_Cache::instance()->file_log("Cache for associated Polylang translation posts' feeds for Title: {{title}} have been purged", $deleted_post_id);
86 90 }
87 91 }
88 92 }