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

112 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace DeliciousBrains\SpinupWp;
4
5 use DeliciousBrains\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;
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 $this->cache->init();
41 $admin_bar->init();
42 $admin_notices->init();
43
44 if ( getenv( 'SPINUPWP_SITE' ) ) {
45 register_activation_hook( $this->path, array( Plugin::class, 'install' ) );
46 register_uninstall_hook( $this->path, array( Plugin::class, 'uninstall' ) );
47 add_action( 'admin_init', array( $this, 'admin_init' ) );
48
49 $site_health = new SiteHealth();
50 $site_health->init();
51 }
52 }
53
54 /**
55 * Perform actions on plugin activation.
56 */
57 public static function install() {
58 $plugin_path = untrailingslashit( dirname( __DIR__ ) );
59 $wpmu_dir = untrailingslashit( WPMU_PLUGIN_DIR );
60 $wpcontent_dir = untrailingslashit( WP_CONTENT_DIR );
61
62 if ( ! file_exists( $wpmu_dir . '/spinupwp-debug-log-path.php' ) ) {
63 wp_mkdir_p( $wpmu_dir );
64 @copy( $plugin_path . '/mu-plugins/spinupwp-debug-log-path.php', $wpmu_dir . '/spinupwp-debug-log-path.php' );
65 }
66
67 if ( file_exists( $wpcontent_dir . '/object-cache.php' ) ) {
68 @unlink( $wpcontent_dir . '/object-cache.php' );
69 }
70
71 @copy( $plugin_path . '/drop-ins/object-cache.php', $wpcontent_dir . '/object-cache.php' );
72
73 if ( function_exists( 'wp_cache_flush' ) ) {
74 wp_cache_flush();
75 }
76 }
77
78 /**
79 * Perform actions on plugin uninstall.
80 */
81 public static function uninstall() {
82 $wpmu_dir = untrailingslashit( WPMU_PLUGIN_DIR );
83 $wpcontent_dir = untrailingslashit( WP_CONTENT_DIR );
84
85 if ( file_exists( $wpmu_dir . '/spinupwp-debug-log-path.php' ) ) {
86 @unlink( $wpmu_dir . '/spinupwp-debug-log-path.php' );
87 }
88
89 if ( function_exists( 'wp_cache_flush' ) ) {
90 wp_cache_flush();
91 }
92
93 if ( file_exists( $wpcontent_dir . '/object-cache.php' ) ) {
94 @unlink( $wpcontent_dir . '/object-cache.php' );
95 }
96
97 delete_site_option( 'spinupwp_redis_cache_disabled' );
98 delete_site_option( 'spinupwp_mail_notice_dismissed' );
99 delete_site_option( 'spinupwp_redis_cache_disabled_notice_dismissed' );
100 }
101
102 /**
103 * Perform actions on admin init.
104 */
105 public function admin_init() {
106 if ( is_plugin_active( 'redis-cache/redis-cache.php' ) ) {
107 deactivate_plugins( 'redis-cache/redis-cache.php' );
108 update_site_option( 'spinupwp_redis_cache_disabled', true );
109 }
110 }
111 }
112