PluginProbe
wpForo Forum / 2.1.0
wpForo Forum v2.1.0
3.1.5 3.1.4 3.1.2 3.1.1 3.1.0 3.0.9 3.0.8 3.0.7 trunk 1.0.0 1.0.1 1.0.2 1.1.0 1.1.1 1.1.2 1.2.0 1.3.0 1.3.1 1.4.0 1.4.1 1.4.10 1.4.11 1.4.12 1.4.13 1.4.2 All 137 releases
wpforo / classes / Cache.php

Cache.php in wpForo Forum 2.1.0, at classes/Cache.php

520 lines 23.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace wpforo\classes;
4
5 use FilesystemIterator;
6
7 // Exit if accessed directly
8 if( ! defined( 'ABSPATH' ) ) exit;
9
10 class Cache {
11 public $object;
12 public $dir;
13 public $lang;
14
15 function __construct() {
16 add_action( 'wpforo_after_init_folders', function( $folders ) {
17 $cache_dir = $folders['cache']['dir'];
18 if( ! is_dir( $cache_dir ) ) $this->dir( $cache_dir );
19 if( ! is_dir( $cache_dir . DIRECTORY_SEPARATOR . 'tag' ) ) $this->mkdir( $cache_dir . DIRECTORY_SEPARATOR . 'tag' );
20 if( ! is_dir( $cache_dir . DIRECTORY_SEPARATOR . 'item' . DIRECTORY_SEPARATOR . 'tag' ) ) $this->mkdir( $cache_dir . DIRECTORY_SEPARATOR . 'item' . DIRECTORY_SEPARATOR . 'tag' );
21 if( ! is_dir( $cache_dir . DIRECTORY_SEPARATOR . 'item' . DIRECTORY_SEPARATOR . 'url' ) ) $this->mkdir( $cache_dir . DIRECTORY_SEPARATOR . 'item' . DIRECTORY_SEPARATOR . 'url' );
22 if( ! is_dir( $cache_dir . DIRECTORY_SEPARATOR . 'item' . DIRECTORY_SEPARATOR . 'avatar' ) ) $this->mkdir( $cache_dir . DIRECTORY_SEPARATOR . 'item' . DIRECTORY_SEPARATOR . 'avatar' );
23 if( ! is_dir( $cache_dir . DIRECTORY_SEPARATOR . 'item' . DIRECTORY_SEPARATOR . 'reaction' ) ) $this->mkdir( $cache_dir . DIRECTORY_SEPARATOR . 'item' . DIRECTORY_SEPARATOR . 'reaction' );
24 if( ! is_dir( $cache_dir . DIRECTORY_SEPARATOR . 'item' . DIRECTORY_SEPARATOR . 'option' ) ) $this->mkdir( $cache_dir . DIRECTORY_SEPARATOR . 'item' . DIRECTORY_SEPARATOR . 'option' );
25
26 $this->dir = $cache_dir;
27 } );
28
29 add_action( 'wpforo_after_set_locale', function( $locale ) { $this->lang = $locale; } );
30
31 add_action( 'wpforo_after_add_board', function( $board ){
32 if( $board['status'] ){
33 WPF()->change_board( $board['boardid'] );
34 wpforo_clean_cache();
35 }
36 } );
37
38 add_action( 'wpforo_after_edit_board', function( $boardid ){
39 $board = WPF()->board->_get_board( $boardid );
40 if( wpfval($board, 'status' ) ){
41 WPF()->change_board( $boardid );
42 wpforo_clean_cache();
43 }
44 } );
45 }
46
47 public function get_key( $type = 'html' ) {
48 if( $type === 'html' ) {
49 $ug = WPF()->current_user_groupid;
50
51 return md5( preg_replace( '#(.+)\#.+?$#is', '$1', $_SERVER['REQUEST_URI'] ) . $ug );
52 }
53 }
54
55 private function dir( $cache_dir ) {
56 $dirs = [
57 $cache_dir,
58 $cache_dir . DIRECTORY_SEPARATOR . 'forum',
59 $cache_dir . DIRECTORY_SEPARATOR . 'topic',
60 $cache_dir . DIRECTORY_SEPARATOR . 'post',
61 $cache_dir . DIRECTORY_SEPARATOR . 'tag',
62 $cache_dir . DIRECTORY_SEPARATOR . 'item',
63 $cache_dir . DIRECTORY_SEPARATOR . 'item' . DIRECTORY_SEPARATOR . 'forum',
64 $cache_dir . DIRECTORY_SEPARATOR . 'item' . DIRECTORY_SEPARATOR . 'topic',
65 $cache_dir . DIRECTORY_SEPARATOR . 'item' . DIRECTORY_SEPARATOR . 'post',
66 $cache_dir . DIRECTORY_SEPARATOR . 'item' . DIRECTORY_SEPARATOR . 'tag',
67 $cache_dir . DIRECTORY_SEPARATOR . 'item' . DIRECTORY_SEPARATOR . 'url',
68 $cache_dir . DIRECTORY_SEPARATOR . 'item' . DIRECTORY_SEPARATOR . 'avatar',
69 $cache_dir . DIRECTORY_SEPARATOR . 'item' . DIRECTORY_SEPARATOR . 'reaction',
70 $cache_dir . DIRECTORY_SEPARATOR . 'item' . DIRECTORY_SEPARATOR . 'option',
71 ];
72 $this->mkdir( $dirs );
73 }
74
75 private function mkdir( $dirs ) {
76 foreach( (array) $dirs as $dir ) {
77 wp_mkdir_p( $dir );
78 wpforo_write_file( $dir . '/index.html', '' );
79 wpforo_write_file( $dir . '/.htaccess', 'deny from all' );
80 }
81 }
82
83 public function on(){
84 return wpforo_setting( 'board', 'cache' );
85 }
86
87 public function get( $key, $type = 'loop', $template = null ) {
88 $template = ( $template ) ?: WPF()->current_object['template'];
89 $loop_templates = [ 'forum', 'topic', 'post', 'tag' ];
90 if( $type === 'loop' && $template ) {
91 if( $this->exists( $key, $template ) ) {
92 if( in_array( $template, $loop_templates ) ) {
93 $cache_file = $this->dir . '/' . $template . '/' . $key;
94 $array = wpforo_get_file_content( $cache_file );
95
96 return @unserialize( $array );
97 }
98 }
99 }
100 }
101
102 public function get_item( $id, $type = 'post', $sub_type = '' ) {
103 if( $id ) {
104 $key = $id . '_' . $this->lang;
105 $domain_path = preg_replace('|https?\:\/\/|is', '', get_site_url() );
106 if( $this->exists( $key, 'item', $type, $sub_type ) ) {
107 $cache_file = $this->dir . '/item/' . $type . '/' . ( $sub_type ? $sub_type . '_' : '' ) . $key;
108 $array = wpforo_get_file_content( $cache_file );
109 $data = @unserialize( $array );
110 if( $type === 'url' ) {
111 // Always make sure the cached URLs are pointed to current website
112 if( strpos( $data, $domain_path ) === FALSE ) return null;
113 }
114 return $data;
115 }
116 }
117 return null;
118 }
119
120 public function get_html() {
121 $template = WPF()->current_object['template'];
122 if( $template == 'forum' ) {
123 $key = $this->get_key();
124 if( $this->exists( $key, $template ) ) {
125 $cache_file = $this->dir . '/' . $template . '/' . $key;
126 $html = wpforo_get_file_content( $cache_file );
127
128 return $this->filter( $html );
129 }
130 }
131
132 return false;
133 }
134
135 public function html( $content ) {
136 /*$template = WPF()->current_object['template'];
137 if( $template === 'forum' ){
138 $key = $this->get_key();
139 $this->create_html( $content, $template, $key );
140 }*/
141 }
142
143 public function create( $mode = 'loop', $cache = [], $type = 'post' ) {
144 if( ! $this->on() ) return false;
145 $template = WPF()->current_object['template'];
146 if( $template == 'forum' ) {
147 $this->check( $this->dir . '/item/post' );
148 }
149
150 if( $mode === 'loop' && $template ) {
151 if( wpfval( $cache, 'tags' ) ) {
152 $this->create_files( $cache['tags'], 'tag' );
153 }
154 if( $template === 'forum' || $template === 'topic' || $template === 'post' ) {
155 $cache = WPF()->forum->get_cache( 'forums' );
156 $this->create_files( $cache, $template );
157 $cache = WPF()->topic->get_cache( 'topics' );
158 $this->create_files( $cache, $template );
159 $cache = WPF()->post->get_cache( 'posts' );
160 $this->create_files( $cache, $template );
161 }
162 } elseif( $mode === 'item' && ! empty( $cache ) ) {
163 $this->create_files( $cache, 'item', $type );
164 }
165 }
166
167 public function create_files( $cache = [], $template = '', $type = '' ) {
168 if( ! empty( $cache ) ) {
169 $type = ( $type ) ? $type . '/' : '';
170 foreach( $cache as $key => $object ) {
171 if( $template == 'item' ) $key = $key . '_' . $this->lang;
172 if( ! $this->exists( $key, $template ) ) {
173 $object = serialize( $object );
174 wpforo_write_file( $this->dir . '/' . $template . '/' . $type . $key, $object );
175 }
176 }
177 }
178 }
179
180 public function create_html( $content, $template = '', $key = '' ) {
181 if( $content ) {
182 if( ! $this->exists( $key, $template ) ) {
183 wpforo_write_file( $this->dir . '/' . $template . '/' . $key, $content );
184 }
185 }
186 }
187
188 public function create_custom( $args = [], $items = [], $template = 'post', $items_count = 0 ) {
189 if( empty( $args ) || ! is_array( $args ) ) return;
190 if( empty( $items ) || ! is_array( $items ) ) return;
191 $cache = [];
192 $hach = serialize( $args );
193 $object_key = md5( $hach . WPF()->current_user_groupid );
194 $cache[ $object_key ]['items'] = $items;
195 $cache[ $object_key ]['items_count'] = $items_count;
196 $this->create_files( $cache, $template );
197 }
198
199 public function filter( $html = '' ) {
200 //exit();
201 $html = preg_replace( '|<div[\s\t]*id=\"wpf\-msg\-box\"|is', '<div style="display:none;"', $html );
202
203 return $html;
204 }
205
206 #################################################################################
207
208 /**
209 * Cleans forum cache
210 *
211 * @param integer Item ID (e.g.: $topicid or $postid) | (!) ID is 0 on dome actions (e.g.: delete actions)
212 * @param string Item Type (e.g.: 'forum', 'topic', 'post', 'user', 'widget', etc...)
213 * @param array Item data as array
214 *
215 * @return NULL
216 * @since 1.2.1
217 *
218 */
219
220 public function clean( $id, $template, $item = [] ) {
221
222 $dirs = [];
223 $userid = ( isset( $item['userid'] ) && $item['userid'] ) ? $item['userid'] : 0;
224 $postid = ( isset( $item['postid'] ) && $item['postid'] ) ? $item['postid'] : 0;
225 $topicid = ( isset( $item['topicid'] ) && $item['topicid'] ) ? $item['topicid'] : 0;
226 $forumid = ( isset( $item['forumid'] ) && $item['forumid'] ) ? $item['forumid'] : 0;
227 $parentid = ( isset( $item['parentid'] ) && $item['parentid'] ) ? $item['parentid'] : 0;
228 $root = ( isset( $item['root'] ) && $item['root'] ) ? $item['root'] : 0;
229 $tagid = ( isset( $item['tagid'] ) && $item['tagid'] ) ? $item['tagid'] : 0;
230
231 WPF()->forum->reset();
232 WPF()->topic->reset();
233 WPF()->post->reset();
234
235 if( $template === 'forum' || $template === 'forum-soft' ) {
236 $id = isset( $id ) ? $id : $forumid;
237 if( $template === 'forum' ) {
238 $dirs = [ $this->dir . '/forum', $this->dir . '/item/forum', $this->dir . '/item/url' ];
239 WPF()->seo->clear_cache();
240 }
241 if( $template === 'forum-soft' ) {
242 $dirs = [ $this->dir . '/forum' ];
243 }
244 if( $id ) {
245 $file = $this->dir . '/item/forum/' . $id . '_' . $this->lang;
246 $this->clean_file( $file );
247 }
248 } elseif( $template === 'topic' || $template === 'topic-first-post' || $template === 'topic-soft' ) {
249 $id = isset( $id ) ? $id : $topicid;
250 if( $template === 'topic' || $template === 'topic-first-post' ) {
251 WPF()->seo->clear_cache();
252 $dirs = [ $this->dir . '/forum', $this->dir . '/topic', $this->dir . '/post' ];
253 }
254 if( $forumid ) {
255 $file = $this->dir . '/item/forum/' . $forumid . '_' . $this->lang;
256 $this->clean_file( $file );
257 }
258 if( $id ) {
259 $file = $this->dir . '/item/topic/' . $id . '_' . $this->lang;
260 $this->clean_file( $file );
261 $file = $this->dir . '/item/url/topic_' . $id . '_' . $this->lang;
262 $this->clean_file( $file );
263 $postid = ( isset( $item['first_postid'] ) && $item['first_postid'] ) ? $item['first_postid'] : 0;
264 if( $postid ) $file = $this->dir . '/item/post/' . $postid . '_' . $this->lang;
265 $this->clean_file( $file );
266 if( $template === 'topic' ) $this->clear_topic_posts_urls( $id );
267 }
268 WPF()->statistic_cache_clean();
269 $this->clear_visitor_tracking();
270 } elseif( $template === 'post' || $template === 'post-soft' ) {
271 $id = isset( $id ) ? $id : $postid;
272 if( $template === 'post' ) {
273 $dirs = [ $this->dir . '/forum', $this->dir . '/topic', $this->dir . '/post' ];
274 }
275 if( $forumid ) {
276 $file = $this->dir . '/item/forum/' . $forumid . '_' . $this->lang;
277 $this->clean_file( $file );
278 }
279 if( $topicid ) {
280 $file = $this->dir . '/item/topic/' . $topicid . '_' . $this->lang;
281 $this->clean_file( $file );
282 }
283 if( $parentid ) {
284 $file = $this->dir . '/item/post/' . $parentid . '_' . $this->lang;
285 $this->clean_file( $file );
286 }
287 if( $root ) {
288 $file = $this->dir . '/item/post/' . $root . '_' . $this->lang;
289 $this->clean_file( $file );
290 }
291 if( $id ) {
292 $file = $this->dir . '/item/post/' . $id . '_' . $this->lang;
293 $this->clean_file( $file );
294 $file = $this->dir . '/item/url/post_' . $id . '_' . $this->lang;
295 $this->clean_file( $file );
296 $this->clear_topic_next_posts_urls( $id, $topicid );
297 }
298 WPF()->statistic_cache_clean();
299 $this->clear_visitor_tracking();
300 } elseif( $template === 'tag' ) {
301 if( $id ) {
302 $file = $this->dir . '/item/tag/' . md5( $id ) . '_' . $this->lang;
303 $this->clean_file( $file );
304 } else {
305 $dirs = [ $this->dir . '/tag' ];
306 }
307 } elseif( $template === 'option' ) {
308 $dirs = [ $this->dir . '/item/option' ];
309 } elseif( $template === 'url' ) {
310 $dirs = [ $this->dir . '/item/url' ];
311 } elseif( $template === 'avatar' ) {
312 if( $id ){
313 $file = $this->dir . '/item/avatar/' . $id . '_' . $this->lang;
314 $this->clean_file( $file );
315 } else {
316 $dirs = [ $this->dir . '/item/avatar' ];
317 }
318 } elseif( $template === 'reaction' ) {
319 if( $id ){
320 $file = $this->dir . '/item/reaction/' . $id . '_' . $this->lang;
321 $this->clean_file( $file );
322 } else {
323 $dirs = [ $this->dir . '/item/reaction' ];
324 }
325 } elseif( $template === 'user' ) {
326 if( wpforo_setting( 'seo', 'seo_profile' ) ) WPF()->seo->clear_cache();
327 } elseif( $template === 'loop' ) {
328 $dirs = [ $this->dir . '/forum', $this->dir . '/topic', $this->dir . '/post' ];
329 WPF()->seo->clear_cache();
330 } elseif( $template === 'item' ) {
331 $dirs = [ $this->dir . '/item/post', $this->dir . '/item/topic', $this->dir . '/item/forum' ];
332 WPF()->seo->clear_cache();
333 } else {
334 $dirs = [ $this->dir . '/forum', $this->dir . '/topic', $this->dir . '/post', $this->dir . '/tag', $this->dir . '/item/post', $this->dir . '/item/topic', $this->dir . '/item/forum', $this->dir . '/item/tag', $this->dir . '/item/url', $this->dir . '/item/avatar', $this->dir . '/item/option' ];
335 WPF()->seo->clear_cache();
336 }
337
338 if( ! empty( $dirs ) ) {
339 foreach( $dirs as $dir ) {
340 $this->clean_files( $dir );
341 }
342 }
343 }
344
345 public function clean_files( $directory ) {
346 $directory = wpforo_fix_dir_sep( $directory );
347 $directory_ns = trim( $directory, DIRECTORY_SEPARATOR ) . DIRECTORY_SEPARATOR . '*';
348 $directory_ws = DIRECTORY_SEPARATOR . trim( $directory, DIRECTORY_SEPARATOR ) . DIRECTORY_SEPARATOR . '*';
349 $glob = glob( $directory_ns );
350 if( empty( $glob ) ) $glob = glob( $directory_ws );
351 foreach( $glob as $item ) {
352 if( strpos( $item, 'index.html' ) !== false || strpos( $item, '.htaccess' ) !== false ) continue;
353 if( ! is_dir( $item ) && file_exists( $item ) ) {
354 @unlink( $item );
355 }
356 }
357 }
358
359 public function clean_file( $file ) {
360 if( ! is_dir( $file ) && file_exists( $file ) ) {
361 @unlink( $file );
362 }
363 }
364
365 public function clear_topic_posts_urls( $topicid ){
366 if( !$topicid ) return;
367 $post_ids = WPF()->db->get_results("SELECT `postid` FROM " . WPF()->tables->posts . " WHERE `topicid` = " . intval( $topicid ), ARRAY_A );
368 if( !empty( $post_ids ) ){
369 foreach( $post_ids as $post_id ){
370 $this->clean_file( $this->dir . '/item/post/' . $post_id['postid'] . '_' . $this->lang );
371 $this->clean_file( $this->dir . '/item/url/post_' . $post_id['postid'] . '_' . $this->lang );
372 }
373 }
374 }
375
376 public function clear_topic_next_posts_urls( $postid, $topicid ){
377 $topicid = ( $topicid ) ? : wpforo_post( $postid, 'topicid' );
378 $post_ids = WPF()->db->get_results("SELECT `postid` FROM " . WPF()->tables->posts . " WHERE `topicid` = " . intval( $topicid ) . " AND `postid` > " . intval( $postid ), ARRAY_A );
379 if( !empty( $post_ids ) ){
380 foreach( $post_ids as $post_id ){
381 $this->clean_file( $this->dir . '/item/post/' . $post_id['postid'] . '_' . $this->lang );
382 $this->clean_file( $this->dir . '/item/url/post_' . $post_id['postid'] . '_' . $this->lang );
383 }
384 }
385 }
386
387 public function exists( $key, $template, $type = '', $sub_type = '' ) {
388 $type = ( $type ) ? $type . '/' : '';
389 if( file_exists( $this->dir . '/' . $template . '/' . $type . ( $sub_type ? $sub_type . '_' : '' ) . $key ) ) {
390 return true;
391 } else {
392 return false;
393 }
394 }
395
396 public function check( $directory ) {
397 $directory = wpforo_fix_dir_sep( $directory );
398 $filecount = 0;
399 if( class_exists( 'FilesystemIterator' ) && is_dir( $directory ) ) {
400 $fi = new FilesystemIterator( $directory, FilesystemIterator::SKIP_DOTS );
401 $filecount = iterator_count( $fi );
402 }
403 if( ! $filecount ) {
404 $directory_ns = trim( $directory, DIRECTORY_SEPARATOR ) . DIRECTORY_SEPARATOR . '*';
405 $directory_ws = DIRECTORY_SEPARATOR . trim( $directory, DIRECTORY_SEPARATOR ) . DIRECTORY_SEPARATOR . '*';
406 $files = glob( $directory_ns );
407 if( empty( $files ) ) $files = glob( $directory_ws );
408 $filecount = count( $files );
409 }
410 if( $filecount > 1000 ) {
411 $this->clean_files( $directory );
412 }
413 }
414
415 public function clear_visitor_tracking() {
416 $keep_vistors_data = apply_filters( 'wpforo_keep_visitors_data', 4000 );
417 $time = (int) current_time( 'timestamp', 1 ) - (int) $keep_vistors_data;
418 $online = (int) current_time( 'timestamp', 1 ) - (int) wpforo_setting( 'profiles', 'online_status_timeout' );
419 if( $time > 1 ) {
420 WPF()->db->query( "DELETE FROM `" . WPF()->tables->visits . "` WHERE `time` < " . intval( $time ) . " OR (`time` < " . intval( $online ) . " AND `userid` = 0)" );
421 }
422 }
423
424 public function cache_plugins(){
425 $board_paths = [];
426 $cache_plugins = [];
427
428 if( is_wpforo_multiboard() ){
429 $boards = WPF()->board->get_boards();
430 if(!empty($boards)){
431 foreach($boards as $board){
432 $board_paths[] = '/' . $board['slug'] . '/';
433 }
434 }
435 } else {
436 $board_paths[] = '/' . WPF()->board->get_current( 'slug' ) . '/';
437 }
438
439 $board_paths[] = '/' . wpforo_settings_get_slug('member') . '/';
440 $board_paths[] = '/' . wpforo_settings_get_slug('register') . '/';
441 $board_paths[] = '/' . wpforo_settings_get_slug('login') . '/';
442 $board_paths[] = '/' . wpforo_settings_get_slug('lostpassword') . '/';
443
444 if (function_exists("wpsc_init")) {
445 //WP Super Cache
446 $cache_plugins['WPSuper']['name'] = 'WP Super Cache';
447 $cache_plugins['WPSuper']['steps'][] = __('Please navigate in Dashboard to Settings > WP Super Cache', 'wpforo');
448 $cache_plugins['WPSuper']['steps'][] = __('Go to Advanced Tab, scroll down to "Rejected URL Strings" option', 'wpforo');
449 $cache_plugins['WPSuper']['steps'][] = __('Insert the URL path(s) of your forum page(s) one per line in the option textarea:', 'wpforo') . ' <br><code>' . implode('</code> <br> <code>', $board_paths) . '</code>';
450 $cache_plugins['WPSuper']['steps'][] = __('Save it and delete all caches.', 'wpforo');
451 }
452 if (defined("LSCWP_V")) {
453 //LiteSpeed Cache
454 $cache_plugins['LiteSpeed']['name'] = 'LiteSpeed Cache';
455 $cache_plugins['LiteSpeed']['steps'][] = __('Please navigate in Dashboard to LiteSpeed Cache > Cache admin page', 'wpforo');
456 $cache_plugins['LiteSpeed']['steps'][] = __('Go to Exclude Tab, find the "Do Not Cache URIs" option', 'wpforo');
457 $cache_plugins['LiteSpeed']['steps'][] = __('Insert the URL path(s) of your forum page(s) one per line in the option textarea:', 'wpforo') . ' <br><code>' . implode('</code> <br> <code>', $board_paths) . '</code>';
458 $cache_plugins['LiteSpeed']['steps'][] = __('Save it and delete all caches.', 'wpforo');
459 }
460 if (function_exists("rocket_clean_post")) {
461 //WP Rocket Cache
462 $cache_plugins['WPRocket']['name'] = 'WP Rocket Cache';
463 $cache_plugins['WPRocket']['steps'][] = __('Please navigate in Dashboard to WP Rocket > Advanced Rules Tab', 'wpforo');
464 $cache_plugins['WPRocket']['steps'][] = __('Scroll down to "Never cache (URLs)" option', 'wpforo');
465 $cache_plugins['WPRocket']['steps'][] = __('Insert the URL path(s) of your forum page(s) one per line with wildcard (.*) in the option textarea:', 'wpforo') . ' <br><code>' . implode('</code> <br> <code>', array_map( function ( $value ){ return $value . '(.*)'; }, $board_paths)) . '</code>';
466 $cache_plugins['WPRocket']['steps'][] = __('Save it and delete all caches.', 'wpforo');
467 }
468 if (function_exists("wpfc_clear_post_cache_by_id")) {
469 //WP Fastest Cache
470 $cache_plugins['WPFastest']['name'] = 'WP Fastest Cache';
471 $cache_plugins['WPFastest']['steps'][] = __('Please navigate in Dashboard to WP Fastest Cache > Exclude Tab', 'wpforo');
472 $cache_plugins['WPFastest']['steps'][] = __('In the "Exclude Pages" section click the [Add New Rule] button', 'wpforo');
473 $cache_plugins['WPFastest']['steps'][] = __('Select [Start with] option in the drop-down menu and insert the URL path(s) of your forum page(s) one per rule in the next field:', 'wpforo') . ' <br><code>' . implode('</code> <br> <code>', $board_paths) . '</code>';
474 $cache_plugins['WPFastest']['steps'][] = __('If you have more than one forum pages (boards) you should create separate rules for each forum board.', 'wpforo');
475 $cache_plugins['WPFastest']['steps'][] = __('Save rules and delete all caches.', 'wpforo');
476 }
477 if (function_exists("w3tc_flush_post")) {
478 //W3 Total Cache
479 $cache_plugins['W3Total']['name'] = 'W3 Total Cache';
480 $cache_plugins['W3Total']['steps'][] = __('Please navigate in Dashboard to Performance > Page Cache admin page', 'wpforo');
481 $cache_plugins['W3Total']['steps'][] = __('Go to Advanced Tab, scroll down to Rejected URL Strings option', 'wpforo');
482 $cache_plugins['W3Total']['steps'][] = __('Scroll to Advanced section and insert the URL path(s) of your forum page(s) one per line in the "Never cache the following pages" textarea:', 'wpforo') . ' <br><code>' . implode('</code> <br> <code>', $board_paths) . '</code>';
483 $cache_plugins['W3Total']['steps'][] = __('Save it and delete all caches.', 'wpforo');
484 }
485 if (is_callable(["WPO_Page_Cache", "delete_single_post_cache"])) {
486 //WP-Optimize Cache
487 $cache_plugins['WPOptimize']['name'] = 'WP-Optimize Cache';
488 $cache_plugins['WPOptimize']['steps'][] = __('Please navigate in Dashboard to WP-Optimize > Cache admin page', 'wpforo');
489 $cache_plugins['WPOptimize']['steps'][] = __('Go to Advanced Settings Tab, find the "URLs to exclude from caching" option', 'wpforo');
490 $cache_plugins['WPOptimize']['steps'][] = __('Insert the URL path(s) of your forum page(s) one per line with wildcard [*] in the option textarea:', 'wpforo') . ' <br><code>' . implode('</code> <br> <code>', array_map( function ( $value ){ return $value . '*'; }, $board_paths)) . '</code>';
491 $cache_plugins['WPOptimize']['steps'][] = __('Save it and delete all caches.', 'wpforo');
492 }
493 if (class_exists("\SiteGround_Optimizer\Supercacher\Supercacher")) {
494 //SiteGround Optimizer
495 $cache_plugins['SiteGround']['name'] = 'SiteGround Optimizer';
496 $cache_plugins['SiteGround']['steps'][] = __('Please navigate in Dashboard to SG Optimizer > Caching admin page', 'wpforo');
497 $cache_plugins['SiteGround']['steps'][] = __('Scroll to Exclude URLs from Caching section and click the "pencil" button, enable it, and click the button again', 'wpforo');
498 $cache_plugins['SiteGround']['steps'][] = __('Insert the URL path(s) of your forum page(s) with wildcard [*] in the pop-up filed:', 'wpforo') . ' <br><code>' . implode('</code> <br> <code>', array_map( function ( $value ){ return $value . '*'; }, $board_paths)) . '</code>';
499 $cache_plugins['SiteGround']['steps'][] = __('Save it and delete all caches.', 'wpforo');
500 }
501 return $cache_plugins;
502 }
503
504 public function cache_plugins_status(){
505 $not_exluded = [];
506 $cache_plugins = $this->cache_plugins();
507 $excluded = wpforo_get_option( 'wpforo_excluded_cache', '', false );
508 $excluded = explode(',', $excluded );
509 if( ! empty( $cache_plugins ) ){
510 foreach( $cache_plugins as $cache_plugin ){
511 if( ! in_array( $cache_plugin['name'], $excluded ) ){
512 $not_exluded[] = $cache_plugin;
513 }
514 }
515 }
516 return $not_exluded;
517 }
518
519 }
520