PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 4.5.2
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v4.5.2
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-translatepress-compatibility.php

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

80 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if (!defined('ABSPATH')) die('No direct access allowed');
3
4 if (!class_exists('WPO_TranslatePress_Compatibility')) :
5 /**
6 * Adds compatibility for TranslatePress plugin.
7 */
8 class WPO_TranslatePress_Compatibility {
9
10 private $trp_settings;
11
12 /**
13 * Constructor.
14 */
15 private function __construct() {
16 // Using the TranslatePress instance retrieve the settings
17 $this->trp_settings = TRP_Translate_Press::get_trp_instance()->get_component('settings')->get_settings();
18 // Add action hooks to delete cache for all languages
19 add_action('wpo_single_post_cache_deleted', array($this, 'translatepress_delete_post_cache_for_all_languages'));
20 add_action('wpo_single_post_feed_cache_deleted', array($this, 'translatepress_delete_post_feed_cache_for_all_languages'));
21 }
22
23 /**
24 * Returns singleton instance.
25 *
26 * @return WPO_TranslatePress_Compatibility
27 */
28 public static function instance() {
29 static $_instance;
30 if (null === $_instance) {
31 $_instance = new self();
32 }
33
34 return $_instance;
35 }
36
37 /**
38 * Deletes cache files for all connected languages for a post.
39 *
40 * @param int $deleted_post_id Post id whose cache file is already deleted.
41 */
42 public function translatepress_delete_post_cache_for_all_languages($deleted_post_id) {
43
44 $deleted_post_url = get_permalink($deleted_post_id);
45 $homepage_url = get_home_url(get_current_blog_id());
46 $post_path = str_replace($homepage_url, "", $deleted_post_url);
47
48 // Retrieve the url slugs from TranslatePress setting options
49 $url_slugs = $this->trp_settings['url-slugs'];
50 foreach ($url_slugs as $value) {
51 // Build url using the url-slugs and the path of the deleted post
52 $possible_lang_url = $homepage_url. '/' . $value . $post_path;
53 WPO_Page_Cache::delete_cache_by_url($possible_lang_url);
54 }
55 if (!empty($url_slugs)) WPO_Page_Cache::instance()->file_log("Cache for associated TranslatePress translation posts for Title: {{title}} have been purged", $deleted_post_id);
56 }
57
58 /**
59 * Deletes cache files for all connected languages for a post feed.
60 *
61 * @param int $deleted_post_id Post id whose cache file for feed is already deleted.
62 */
63 public function translatepress_delete_post_feed_cache_for_all_languages($deleted_post_id) {
64
65 $deleted_post_url = get_permalink($deleted_post_id);
66 $homepage_url = get_home_url(get_current_blog_id());
67 $post_path = str_replace($homepage_url, "", $deleted_post_url);
68
69 // Retrieve the url slugs from TranslatePress setting options
70 $url_slugs = $this->trp_settings['url-slugs'];
71 foreach ($url_slugs as $value) {
72 // Build url using the url-slugs and the path of the deleted post
73 $possible_lang_url = $homepage_url.'/'. $value . untrailingslashit($post_path) . '/feed/';
74 WPO_Page_Cache::delete_cache_by_url($possible_lang_url);
75 }
76 if (!empty($url_slugs)) WPO_Page_Cache::instance()->file_log("Cache for associated TranslatePress translation posts' feeds for Title: {{title}} have been purged", $deleted_post_id);
77 }
78 }
79 endif;
80