PluginProbe
BerqWP – All-In-One Optimization for Core Web Vitals, Cache, CDN, Images, CSS & JavaScript / trunk
BerqWP – All-In-One Optimization for Core Web Vitals, Cache, CDN, Images, CSS & JavaScript vtrunk
4.1.15 4.1.14 4.1.13 4.1.12 4.1.11 4.1.10 4.0.30 4.0.29 4.0.28 4.0.27 4.0.26 4.0.24 4.0.25 4.0.23 4.0.22 4.0.21 4.0.19 4.0.18 4.0.17 4.0.16 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 All 169 releases
searchpro / api / store_cache.php

store_cache.php in BerqWP – All-In-One Optimization for Core Web Vitals, Cache, CDN, Images, CSS & JavaScript trunk, at api/store_cache.php

53 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if (!defined('ABSPATH')) exit;
3
4 $status = sanitize_text_field($request->get_param('status'));
5 $key = sanitize_text_field($request->get_param('key'));
6 $html = base64_decode($request->get_param('html'));
7 $slug = $request->get_param('page_slug');
8
9 if ($status == 'success' && !empty($request->get_param('html'))) {
10 global $berq_log;
11
12 // Allow other plugins to modify cache html
13 $html = apply_filters( 'berqwp_cache_buffer', $html );
14
15 // Define the cache directory
16 $cache_directory = bwp_get_cache_dir();
17
18 // Create the cache directory if it doesn't exist
19 if (!file_exists($cache_directory)) {
20 mkdir($cache_directory, 0755, true);
21 }
22
23 $cache_file = $cache_directory . md5($slug) . '.html';
24
25 if ($html) {
26 $berq_log->info("Empty html cache: $page_url");
27 exit;
28 }
29
30 // update_option( md5($slug), $key );
31 file_put_contents($cache_file, $html);
32
33 if (bwp_is_gzip_supported()) {
34 $cache_file = $cache_directory . md5($slug) . '.gz';
35 $html = gzencode($html, 9);
36 file_put_contents($cache_file, $html);
37 }
38
39
40 do_action('berqwp_stored_page_cache', $slug);
41
42 $berq_log->info("Stored cache for $slug");
43
44 // Cache is stored which means connection is stable
45 // Delete connection test error transient
46 $check_connection = bwp_check_connection();
47 if ( $check_connection['status'] == 'error' ) {
48 delete_transient('berqwp_connection_status');
49 }
50
51
52 }
53 unset($html); // release memory