PluginProbe ʕ •ᴥ•ʔ
NitroPack – Performance, Page Speed & Cache Plugin for Core Web Vitals, CDN & Image Optimization / trunk
NitroPack – Performance, Page Speed & Cache Plugin for Core Web Vitals, CDN & Image Optimization vtrunk
1.19.8 1.19.7 1.19.6 1.19.5 trunk 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.11.0 1.12.0 1.13.0 1.14.0 1.15.0 1.15.1 1.15.2 1.15.3 1.16.0 1.16.1 1.16.2 1.16.3 1.16.4 1.16.5 1.16.6 1.16.7 1.16.8 1.17.0 1.17.6 1.17.7 1.17.8 1.17.9 1.18.0 1.18.1 1.18.2 1.18.3 1.18.4 1.18.5 1.18.6 1.18.7 1.18.8 1.18.9 1.19.0 1.19.1 1.19.2 1.19.3 1.19.4 1.3.19 1.3.20 1.4.0 1.4.1 1.5.0 1.5.1 1.5.10 1.5.11 1.5.12 1.5.13 1.5.14 1.5.15 1.5.16 1.5.17 1.5.18 1.5.19 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.7.0 1.7.1 1.8.0 1.8.1 1.8.3 1.9.0 1.9.1 1.9.2
nitropack / classes / WordPress / AdvancedCache / AdvancedCache.php
nitropack / classes / WordPress / AdvancedCache Last commit date
AdvancedCache.php 4 days ago advanced-cache.php 4 days ago
AdvancedCache.php
66 lines
1 <?php
2
3 namespace Nitropack\WordPress\AdvancedCache;
4
5 /**
6 * Here we handle the installation and uninstallation of the advanced_cache.php file stored in wp-content folder.
7 */
8 class AdvancedCache {
9 public function __construct() {
10 if ( $this->has_advanced_cache() ) {
11 // Handle automated updates
12 if ( ! defined( "NITROPACK_ADVANCED_CACHE_VERSION" ) || NITROPACK_VERSION != NITROPACK_ADVANCED_CACHE_VERSION ) {
13 add_action( 'plugins_loaded', [ $this, 'install_advanced_cache' ] );
14 }
15 }
16 }
17
18 /**
19 * @return void|false Returns false if the advanced-cache.php file cannot be created, otherwise returns void.
20 * @description Installs the advanced-cache.php file in the WP_CONTENT_DIR directory. This file is required for NitroPack to work properly. If the file cannot be created, the function returns
21 */
22 public function install_advanced_cache() {
23 $conflictingPlugins = \NitroPack\WordPress\ConflictingPlugins::getInstance();
24 $nitropack_is_conflicting_plugin_active = $conflictingPlugins->nitropack_is_conflicting_plugin_active();
25 if ( $nitropack_is_conflicting_plugin_active || ! nitropack_is_advanced_cache_allowed() ) {
26 return false;
27 }
28
29 $templatePath = nitropack_trailingslashit( NITROPACK_PLUGIN_DIR ) . "/classes/WordPress/AdvancedCache/advanced-cache.php";
30 if ( file_exists( $templatePath ) ) {
31 $contents = file_get_contents( $templatePath );
32 $contents = str_replace( "/*NITROPACK_FUNCTIONS_FILE*/", NITROPACK_PLUGIN_DIR . 'functions.php', $contents );
33 $contents = str_replace( "/*NITROPACK_ABSPATH*/", ABSPATH, $contents );
34 $contents = str_replace( "/*LOGIN_COOKIES*/", defined( "LOGGED_IN_COOKIE" ) ? LOGGED_IN_COOKIE : "", $contents );
35 $contents = str_replace( "/*NP_VERSION*/", NITROPACK_VERSION, $contents );
36
37 $advancedCacheFile = nitropack_trailingslashit( WP_CONTENT_DIR ) . 'advanced-cache.php';
38 return WP_DEBUG
39 ? file_put_contents( $advancedCacheFile, $contents )
40 : @file_put_contents( $advancedCacheFile, $contents );
41 }
42 }
43
44 /**
45 * @return void|false Returns false if the advanced-cache.php file cannot be created, otherwise returns void.
46 * @description Uninstalls the advanced-cache.php file in the WP_CONTENT_DIR directory.
47 */
48 public function uninstall_advanced_cache() {
49 $advancedCacheFile = nitropack_trailingslashit( WP_CONTENT_DIR ) . 'advanced-cache.php';
50 if ( file_exists( $advancedCacheFile ) ) {
51 if ( WP_DEBUG ) {
52 return file_put_contents( $advancedCacheFile, "" );
53 } else {
54 return @file_put_contents( $advancedCacheFile, "" );
55 }
56 }
57 }
58
59 /**
60 * @return bool
61 * @description Checks whether the constant NITROPACK_ADVANCED_CACHE is defined.
62 */
63 public function has_advanced_cache() {
64 return defined( 'NITROPACK_ADVANCED_CACHE' );
65 }
66 }