PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 3.2.22
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v3.2.22
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
wp-optimize / compatibility / class-wpo-polylang-compatibility.php

class-wpo-polylang-compatibility.php in WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance 3.2.22, at compatibility/class-wpo-polylang-compatibility.php

89 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if (!defined('ABSPATH')) {
3 die('No direct access allowed');
4 }
5
6 /**
7 * Adds compatibility for Polylang plugin.
8 */
9 class WPO_Polylang_Compatibility {
10
11 /**
12 * Instance of this class
13 *
14 * @var WPO_Polylang_Compatibility|null
15 */
16 protected static $instance = null;
17
18 /**
19 * Constructor.
20 */
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'));
30 }
31
32 /**
33 * Returns singleton instance.
34 *
35 * @return WPO_Polylang_Compatibility
36 */
37 public static function instance() {
38 if (null == self::$instance) {
39 self::$instance = new self;
40 }
41
42 return self::$instance;
43 }
44
45 /**
46 * Deletes cache files for all connected languages for a post.
47 *
48 * @param int $deleted_post_id Post id whose cache file is already deleted.
49 */
50 public function polylang_delete_post_cache_for_all_languages($deleted_post_id) {
51
52 // Check if polylang translation function is available
53 if (!function_exists('pll_get_post_translations')) {
54 return;
55 }
56
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 }
64 }
65 }
66
67 /**
68 * Deletes cache files for all connected languages for a post feed.
69 *
70 * @param int $deleted_post_id Post id whose cache file for feed is already deleted.
71 */
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;
77 }
78
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 }
86 }
87 }
88 }
89