PluginProbe
SpinupWP / 1.9.1
SpinupWP v1.9.1
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.1, at src/Plugin.php

159 lines 4.0 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 ( new SubdomainUrlRewriter() )->init();
55 }
56
57 add_filter( 'spinupwp_should_use_object_cache_dropin', array( $this, 'should_use_object_cache_dropin' ) );
58 }
59
60 /**
61 * Perform actions on plugin activation.
62 */
63 public static function install() {
64 $plugin_path = untrailingslashit( dirname( __DIR__ ) );
65 $wpmu_dir = untrailingslashit( WPMU_PLUGIN_DIR );
66
67 if ( ! file_exists( $wpmu_dir . '/spinupwp-debug-log-path.php' ) ) {
68 wp_mkdir_p( $wpmu_dir );
69 @copy( $plugin_path . '/mu-plugins/spinupwp-debug-log-path.php', $wpmu_dir . '/spinupwp-debug-log-path.php' );
70 }
71
72 self::update_object_cache_dropin();
73 }
74
75 /**
76 * Perform the update of the object-cache.php drop-in
77 *
78 * @return bool
79 */
80 public static function update_object_cache_dropin() {
81 if ( ! apply_filters( 'spinupwp_should_use_object_cache_dropin', true ) ) {
82 return false;
83 }
84
85 $wpcontent_dir = untrailingslashit( WP_CONTENT_DIR );
86 $plugin_path = untrailingslashit( dirname( __DIR__ ) );
87
88 $existing_backed_up = false;
89 if ( file_exists( $wpcontent_dir . '/object-cache.php' ) ) {
90 $existing_backed_up = @copy( $wpcontent_dir . '/object-cache.php', $wpcontent_dir . '/object-cache.php.bak' );
91 @unlink( $wpcontent_dir . '/object-cache.php' );
92 }
93
94 $result = @copy( $plugin_path . '/drop-ins/object-cache.php', $wpcontent_dir . '/object-cache.php' );
95
96 if ( $existing_backed_up ) {
97 if ( $result ) {
98 @unlink( $wpcontent_dir . '/object-cache.php.bak' );
99 } else {
100 @rename( $wpcontent_dir . '/object-cache.php.bak', $wpcontent_dir . '/object-cache.php' );
101 }
102 }
103
104 if ( $result && function_exists( 'wp_cache_flush' ) ) {
105 wp_cache_flush();
106 }
107
108 return $result;
109 }
110
111 /**
112 * @param bool $check
113 *
114 * @return bool
115 */
116 public function should_use_object_cache_dropin( $check ) {
117 if ( defined( 'RedisCachePro\Version' ) ) {
118 // Don't use our object-cache.php drop-in if the site is using the Object Cache Pro plugin
119 return false;
120 }
121
122 return $check;
123 }
124
125 /**
126 * Perform actions on plugin uninstall.
127 */
128 public static function uninstall() {
129 $wpmu_dir = untrailingslashit( WPMU_PLUGIN_DIR );
130 $wpcontent_dir = untrailingslashit( WP_CONTENT_DIR );
131
132 if ( file_exists( $wpmu_dir . '/spinupwp-debug-log-path.php' ) ) {
133 @unlink( $wpmu_dir . '/spinupwp-debug-log-path.php' );
134 }
135
136 if ( function_exists( 'wp_cache_flush' ) ) {
137 wp_cache_flush();
138 }
139
140 if ( file_exists( $wpcontent_dir . '/object-cache.php' ) ) {
141 @unlink( $wpcontent_dir . '/object-cache.php' );
142 }
143
144 delete_site_option( 'spinupwp_redis_cache_disabled' );
145 delete_site_option( 'spinupwp_mail_notice_dismissed' );
146 delete_site_option( 'spinupwp_redis_cache_disabled_notice_dismissed' );
147 }
148
149 /**
150 * Perform actions on admin init.
151 */
152 public function admin_init() {
153 if ( is_plugin_active( 'redis-cache/redis-cache.php' ) ) {
154 deactivate_plugins( 'redis-cache/redis-cache.php' );
155 update_site_option( 'spinupwp_redis_cache_disabled', true );
156 }
157 }
158 }
159