PluginProbe
SpinupWP / 1.9.0
SpinupWP v1.9.0
trunk 1.0 1.0.1 1.0.2 1.0.3 1.1 1.1.1 1.1.2 1.2 1.3 1.4 1.4.1 1.4.2 1.5 1.5.1 1.6 1.7 1.7.1 1.8.0 1.9.0 1.9.1
spinupwp / src / Plugin.php

Plugin.php in SpinupWP 1.9.0, at src/Plugin.php

158 lines 3.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace SpinupWp;
4
5 use SpinupWp\Cli\Commands;
6
7 class Plugin {
8
9 /**
10 * @var string
11 */
12 public $path;
13
14 /**
15 * @var string
16 */
17 public $url;
18
19 /**
20 * @var Cache
21 */
22 public $cache;
23
24 public function __construct( $path ) {
25 $this->path = $path;
26 $this->url = plugin_dir_url( $path );
27 }
28
29 /**
30 * Run the SpinupWP plugin.
31 */
32 public function run() {
33 $admin_bar = new AdminBar( $this->url );
34 $admin_notices = new AdminNotices( $this->url );
35 $cli = new Cli;
36
37 $cli->register_command( 'spinupwp', Commands::class );
38 $this->cache = new Cache( $admin_bar, $cli );
39
40 $compatibility = new Compatibility( $this->cache );
41
42 $this->cache->init();
43 $admin_bar->init();
44 $admin_notices->init();
45 $compatibility->init();
46
47 if ( getenv( 'SPINUPWP_SITE' ) ) {
48 register_activation_hook( $this->path, array( Plugin::class, 'install' ) );
49 register_uninstall_hook( $this->path, array( Plugin::class, 'uninstall' ) );
50 add_action( 'admin_init', array( $this, 'admin_init' ) );
51
52 ( new MagicLogin() )->init();
53 ( new SiteHealth() )->init();
54 }
55
56 add_filter( 'spinupwp_should_use_object_cache_dropin', array( $this, 'should_use_object_cache_dropin' ) );
57 }
58
59 /**
60 * Perform actions on plugin activation.
61 */
62 public static function install() {
63 $plugin_path = untrailingslashit( dirname( __DIR__ ) );
64 $wpmu_dir = untrailingslashit( WPMU_PLUGIN_DIR );
65
66 if ( ! file_exists( $wpmu_dir . '/spinupwp-debug-log-path.php' ) ) {
67 wp_mkdir_p( $wpmu_dir );
68 @copy( $plugin_path . '/mu-plugins/spinupwp-debug-log-path.php', $wpmu_dir . '/spinupwp-debug-log-path.php' );
69 }
70
71 self::update_object_cache_dropin();
72 }
73
74 /**
75 * Perform the update of the object-cache.php drop-in
76 *
77 * @return bool
78 */
79 public static function update_object_cache_dropin() {
80 if ( ! apply_filters( 'spinupwp_should_use_object_cache_dropin', true ) ) {
81 return false;
82 }
83
84 $wpcontent_dir = untrailingslashit( WP_CONTENT_DIR );
85 $plugin_path = untrailingslashit( dirname( __DIR__ ) );
86
87 $existing_backed_up = false;
88 if ( file_exists( $wpcontent_dir . '/object-cache.php' ) ) {
89 $existing_backed_up = @copy( $wpcontent_dir . '/object-cache.php', $wpcontent_dir . '/object-cache.php.bak' );
90 @unlink( $wpcontent_dir . '/object-cache.php' );
91 }
92
93 $result = @copy( $plugin_path . '/drop-ins/object-cache.php', $wpcontent_dir . '/object-cache.php' );
94
95 if ( $existing_backed_up ) {
96 if ( $result ) {
97 @unlink( $wpcontent_dir . '/object-cache.php.bak' );
98 } else {
99 @rename( $wpcontent_dir . '/object-cache.php.bak', $wpcontent_dir . '/object-cache.php' );
100 }
101 }
102
103 if ( $result && function_exists( 'wp_cache_flush' ) ) {
104 wp_cache_flush();
105 }
106
107 return $result;
108 }
109
110 /**
111 * @param bool $check
112 *
113 * @return bool
114 */
115 public function should_use_object_cache_dropin( $check ) {
116 if ( defined( 'RedisCachePro\Version' ) ) {
117 // Don't use our object-cache.php drop-in if the site is using the Object Cache Pro plugin
118 return false;
119 }
120
121 return $check;
122 }
123
124 /**
125 * Perform actions on plugin uninstall.
126 */
127 public static function uninstall() {
128 $wpmu_dir = untrailingslashit( WPMU_PLUGIN_DIR );
129 $wpcontent_dir = untrailingslashit( WP_CONTENT_DIR );
130
131 if ( file_exists( $wpmu_dir . '/spinupwp-debug-log-path.php' ) ) {
132 @unlink( $wpmu_dir . '/spinupwp-debug-log-path.php' );
133 }
134
135 if ( function_exists( 'wp_cache_flush' ) ) {
136 wp_cache_flush();
137 }
138
139 if ( file_exists( $wpcontent_dir . '/object-cache.php' ) ) {
140 @unlink( $wpcontent_dir . '/object-cache.php' );
141 }
142
143 delete_site_option( 'spinupwp_redis_cache_disabled' );
144 delete_site_option( 'spinupwp_mail_notice_dismissed' );
145 delete_site_option( 'spinupwp_redis_cache_disabled_notice_dismissed' );
146 }
147
148 /**
149 * Perform actions on admin init.
150 */
151 public function admin_init() {
152 if ( is_plugin_active( 'redis-cache/redis-cache.php' ) ) {
153 deactivate_plugins( 'redis-cache/redis-cache.php' );
154 update_site_option( 'spinupwp_redis_cache_disabled', true );
155 }
156 }
157 }
158