PluginProbe
BerqWP – All-In-One Optimization for Core Web Vitals, Cache, CDN, Images, CSS & JavaScript / 4.1.13
BerqWP – All-In-One Optimization for Core Web Vitals, Cache, CDN, Images, CSS & JavaScript v4.1.13
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_javascript_cache.php

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

43 lines 1.1 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 exit;
4 }
5
6 $js_urls = $request->get_param('js_urls');
7
8 if (empty($js_urls)) {
9 return new WP_REST_Response('No JavaScript URLs provided.', 400);
10 }
11
12 $return_url = [];
13
14 foreach ($js_urls as $js_url) {
15 // $response = wp_remote_get($js_url);
16 $response = bwp_wp_remote_get($js_url);
17
18 // Download and save the content of each JS file
19 $content = file_get_contents($js_url);
20 $file_name = basename(parse_url($js_url, PHP_URL_PATH)); // Remove GET parameters
21 $file_path = optifer_cache . 'js/' . md5($js_url) . '_' . $file_name;
22
23 // Create the directory if it doesn't exist
24 if (!file_exists(optifer_cache . 'js/')) {
25 mkdir(optifer_cache . 'js/', 0755, true);
26 }
27
28 // Save the content to the cache directory
29 file_put_contents($file_path, $content);
30
31 unset($content, $response);
32
33 $return_url[md5($js_url)] = get_site_url() . '/wp-content/cache/berqwp/js/' . md5($js_url) . '_' . $file_name;
34
35 }
36
37 echo wp_json_encode(
38 [
39 "status" => "success",
40 "urls" => $return_url
41 ]
42 );
43 exit;