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

115 lines 2.8 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( $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 $site_health = new SiteHealth();
53 $site_health->init();
54 }
55 }
56
57 /**
58 * Perform actions on plugin activation.
59 */
60 public static function install() {
61 $plugin_path = untrailingslashit( dirname( __DIR__ ) );
62 $wpmu_dir = untrailingslashit( WPMU_PLUGIN_DIR );
63 $wpcontent_dir = untrailingslashit( WP_CONTENT_DIR );
64
65 if ( ! file_exists( $wpmu_dir . '/spinupwp-debug-log-path.php' ) ) {
66 wp_mkdir_p( $wpmu_dir );
67 @copy( $plugin_path . '/mu-plugins/spinupwp-debug-log-path.php', $wpmu_dir . '/spinupwp-debug-log-path.php' );
68 }
69
70 if ( file_exists( $wpcontent_dir . '/object-cache.php' ) ) {
71 @unlink( $wpcontent_dir . '/object-cache.php' );
72 }
73
74 @copy( $plugin_path . '/drop-ins/object-cache.php', $wpcontent_dir . '/object-cache.php' );
75
76 if ( function_exists( 'wp_cache_flush' ) ) {
77 wp_cache_flush();
78 }
79 }
80
81 /**
82 * Perform actions on plugin uninstall.
83 */
84 public static function uninstall() {
85 $wpmu_dir = untrailingslashit( WPMU_PLUGIN_DIR );
86 $wpcontent_dir = untrailingslashit( WP_CONTENT_DIR );
87
88 if ( file_exists( $wpmu_dir . '/spinupwp-debug-log-path.php' ) ) {
89 @unlink( $wpmu_dir . '/spinupwp-debug-log-path.php' );
90 }
91
92 if ( function_exists( 'wp_cache_flush' ) ) {
93 wp_cache_flush();
94 }
95
96 if ( file_exists( $wpcontent_dir . '/object-cache.php' ) ) {
97 @unlink( $wpcontent_dir . '/object-cache.php' );
98 }
99
100 delete_site_option( 'spinupwp_redis_cache_disabled' );
101 delete_site_option( 'spinupwp_mail_notice_dismissed' );
102 delete_site_option( 'spinupwp_redis_cache_disabled_notice_dismissed' );
103 }
104
105 /**
106 * Perform actions on admin init.
107 */
108 public function admin_init() {
109 if ( is_plugin_active( 'redis-cache/redis-cache.php' ) ) {
110 deactivate_plugins( 'redis-cache/redis-cache.php' );
111 update_site_option( 'spinupwp_redis_cache_disabled', true );
112 }
113 }
114 }
115