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 +36 -31 4.5.4 → 4.7.0 View file →
@@ -13,16 +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 - // Add action hooks to delete cache for all languages
23 - add_action('wpo_single_post_cache_deleted', array($this, 'polylang_delete_post_cache_for_all_languages'));
24 - 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'));
25 24 }
26 25
27 26 /**
28 27 * Returns singleton instance.
@@ -37,28 +36,41 @@
37 36 return self::$instance;
38 37 }
39 38
40 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 + /**
41 58 * Deletes cache files for all connected languages for a post.
42 59 *
43 60 * @param int $deleted_post_id Post id whose cache file is already deleted.
61 + * @return void
44 62 */
45 - 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);
46 65
47 - // Check if polylang translation function is available
48 - if (!function_exists('pll_get_post_translations')) {
49 - return;
66 + foreach ($related_ids as $post_id) {
67 + WPO_Page_Cache::really_delete_single_post_cache($post_id);
50 68 }
51 69
52 - $translated_post_ids = pll_get_post_translations($deleted_post_id);
53 -
54 - // Delete cache for each translated post
55 - foreach ($translated_post_ids as $post_id) {
56 - if ($deleted_post_id !== $post_id) {
57 - WPO_Page_Cache::really_delete_single_post_cache($post_id);
58 - }
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);
59 72 }
60 - if (!empty($translated_post_ids)) WPO_Page_Cache::instance()->file_log("Cache for associated Polylang translation posts for Title: {{title}} have been purged", $deleted_post_id);
61 73 }
62 74
63 75 /**
64 76 * Deletes cache files for all connected languages for a post feed.
@@ -63,25 +75,18 @@
63 75 /**
64 76 * Deletes cache files for all connected languages for a post feed.
65 77 *
66 78 * @param int $deleted_post_id Post id whose cache file for feed is already deleted.
79 + * @return void
67 80 */
68 - public function polylang_delete_post_feed_cache_for_all_languages($deleted_post_id) {
69 -
70 - // Check if polylang translation function is available
71 - if (!function_exists('pll_get_post_translations')) {
72 - 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);
73 86 }
74 87
75 - $translated_post_ids = pll_get_post_translations($deleted_post_id);
76 - $is_cache_purged = false;
77 -
78 - // Delete cache for each translated post
79 - foreach ($translated_post_ids as $post_id) {
80 - if ($deleted_post_id !== $post_id) {
81 - WPO_Page_Cache::really_delete_post_feed_cache($post_id);
82 - $is_cache_purged = true;
83 - }
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);
84 90 }
85 - if ($is_cache_purged) WPO_Page_Cache::instance()->file_log("Cache for associated Polylang translation posts' feeds for Title: {{title}} have been purged", $deleted_post_id);
86 91 }
87 92 }