PluginProbe
Solid Performance – Your No-Code Caching, Performance, & Page Speed Solution / 1.1.0
Solid Performance – Your No-Code Caching, Performance, & Page Speed Solution v1.1.0
2.0.1 trunk 1.0.0 1.1.0 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.5.0 1.6.0 1.6.1 1.7.0 1.7.1 1.8.0 1.9.0 2.0.0
solid-performance / src / Performance / Plugin / Activator.php

Activator.php in Solid Performance – Your No-Code Caching, Performance, & Page Speed Solution 1.1.0, at src/Performance/Plugin/Activator.php

129 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * All functionality related to activating the plugin.
4 *
5 * @since 0.1.0
6 *
7 * @package SolidWP\Performance
8 */
9
10 declare( strict_types=1 );
11
12 namespace SolidWP\Performance\Plugin;
13
14 use SolidWP\Performance\Config\Advanced_Cache;
15 use SolidWP\Performance\Config\Config;
16 use SolidWP\Performance\Config\Strategies\Network;
17 use SolidWP\Performance\Config\Strategies\Network_File;
18 use SolidWP\Performance\Config\Strategies\Pipeline;
19 use SolidWP\Performance\Config\Strategies\Site;
20 use SolidWP\Performance\Config\Strategies\Site_File;
21 use SolidWP\Performance\Config\WP_Config;
22 use SolidWP\Performance\Container;
23
24 if ( ! defined( 'ABSPATH' ) ) {
25 exit;
26 }
27
28 /**
29 * Handles actions that should run when the plugin is activated.
30 *
31 * @since 0.1.0
32 *
33 * @package SolidWP\Performance
34 */
35 final class Activator {
36
37 /**
38 * @var Container
39 */
40 private Container $container;
41
42 /**
43 * @param Container $container The container.
44 */
45 public function __construct( Container $container ) {
46 $this->container = $container;
47 }
48
49 /**
50 * Activation hook.
51 *
52 * @since 0.1.0
53 *
54 * @return void
55 */
56 public function __invoke(): void {
57 $this->advanced_cache_dropin_init();
58 $this->cache_directory_init();
59 $this->wp_cache_init();
60 $this->initialize_settings();
61 }
62
63 /**
64 * Ensure that the advanced-cache.php drop-in is copied into place.
65 *
66 * @since 0.1.0
67 *
68 * @return void
69 */
70 private function advanced_cache_dropin_init(): void {
71 $this->container->get( Advanced_Cache::class )->generate();
72 }
73
74 /**
75 * Ensure that the cache directory exists.
76 *
77 * @since 0.1.0
78 *
79 * @return void
80 */
81 private function cache_directory_init(): void {
82 if ( ! is_dir( swpsp_config_get( 'page_cache.cache_dir' ) ) ) {
83 wp_mkdir_p( swpsp_config_get( 'page_cache.cache_dir' ) );
84 }
85 }
86
87
88 /**
89 * Set the WP_CACHE constant.
90 *
91 * @since 0.1.0
92 *
93 * @return void
94 */
95 private function wp_cache_init(): void {
96 $this->container->get( WP_Config::class )->set_wp_cache( 'true' );
97 }
98
99 /**
100 * Saves a set of default values in the config.
101 *
102 * @since 0.1.0
103 *
104 * @return void
105 */
106 private function initialize_settings(): void {
107 $pipeline = new Pipeline( $this->container );
108
109 $pipeline->pipes(
110 [
111 Site::class,
112 Site_File::class,
113 ]
114 );
115
116 if ( is_multisite() ) {
117 $pipeline->pipe(
118 [
119 Network::class,
120 Network_File::class,
121 ]
122 );
123 }
124
125 $config = new Config( $pipeline );
126 $config->save();
127 }
128 }
129