| 1 |
<?php |
| 2 |
|
| 3 |
namespace DeliciousBrains\SpinupWp; |
| 4 |
|
| 5 |
class Plugin { |
| 6 |
|
| 7 |
/** |
| 8 |
* @var string |
| 9 |
*/ |
| 10 |
public $path; |
| 11 |
|
| 12 |
/** |
| 13 |
* @var string |
| 14 |
*/ |
| 15 |
public $url; |
| 16 |
|
| 17 |
/** |
| 18 |
* @var Cache |
| 19 |
*/ |
| 20 |
public $cache; |
| 21 |
|
| 22 |
public function __construct( $path ) { |
| 23 |
$this->path = $path; |
| 24 |
$this->url = plugin_dir_url( $path ); |
| 25 |
} |
| 26 |
|
| 27 |
/** |
| 28 |
* Run the SpinupWP plugin. |
| 29 |
*/ |
| 30 |
public function run() { |
| 31 |
if ( ! getenv( 'SPINUPWP_SITE' ) ) { |
| 32 |
return; |
| 33 |
} |
| 34 |
|
| 35 |
$admin_bar = new AdminBar; |
| 36 |
$admin_notices = new AdminNotices( $this->url ); |
| 37 |
$this->cache = new Cache( $admin_bar, new Cli ); |
| 38 |
|
| 39 |
$this->cache->init(); |
| 40 |
$admin_bar->init(); |
| 41 |
$admin_notices->init(); |
| 42 |
|
| 43 |
register_activation_hook( $this->path, array( Plugin::class, 'install' ) ); |
| 44 |
register_uninstall_hook( $this->path, array( Plugin::class, 'uninstall' ) ); |
| 45 |
add_action( 'admin_init', array( $this, 'admin_init' ) ); |
| 46 |
} |
| 47 |
|
| 48 |
/** |
| 49 |
* Perform actions on plugin activation. |
| 50 |
*/ |
| 51 |
public static function install() { |
| 52 |
$plugin_path = untrailingslashit( dirname( __DIR__ ) ); |
| 53 |
$wpmu_dir = untrailingslashit( WPMU_PLUGIN_DIR ); |
| 54 |
$wpcontent_dir = untrailingslashit( WP_CONTENT_DIR ); |
| 55 |
|
| 56 |
if ( ! file_exists( $wpmu_dir . '/spinupwp-debug-log-path.php' ) ) { |
| 57 |
wp_mkdir_p( $wpmu_dir ); |
| 58 |
@copy( $plugin_path . '/mu-plugins/spinupwp-debug-log-path.php', $wpmu_dir . '/spinupwp-debug-log-path.php' ); |
| 59 |
} |
| 60 |
|
| 61 |
if ( file_exists( $wpcontent_dir . '/object-cache.php' ) ) { |
| 62 |
@unlink( $wpcontent_dir . '/object-cache.php' ); |
| 63 |
} |
| 64 |
|
| 65 |
@copy( $plugin_path . '/drop-ins/object-cache.php', $wpcontent_dir . '/object-cache.php' ); |
| 66 |
|
| 67 |
if ( function_exists( 'wp_cache_flush' ) ) { |
| 68 |
wp_cache_flush(); |
| 69 |
} |
| 70 |
} |
| 71 |
|
| 72 |
/** |
| 73 |
* Perform actions on plugin uninstall. |
| 74 |
*/ |
| 75 |
public static function uninstall() { |
| 76 |
$wpmu_dir = untrailingslashit( WPMU_PLUGIN_DIR ); |
| 77 |
$wpcontent_dir = untrailingslashit( WP_CONTENT_DIR ); |
| 78 |
|
| 79 |
if ( file_exists( $wpmu_dir . '/spinupwp-debug-log-path.php' ) ) { |
| 80 |
@unlink( $wpmu_dir . '/spinupwp-debug-log-path.php' ); |
| 81 |
} |
| 82 |
|
| 83 |
if ( function_exists( 'wp_cache_flush' ) ) { |
| 84 |
wp_cache_flush(); |
| 85 |
} |
| 86 |
|
| 87 |
if ( file_exists( $wpcontent_dir . '/object-cache.php' ) ) { |
| 88 |
@unlink( $wpcontent_dir . '/object-cache.php' ); |
| 89 |
} |
| 90 |
|
| 91 |
delete_site_option( 'spinupwp_redis_cache_disabled' ); |
| 92 |
delete_site_option( 'spinupwp_mail_notice_dismissed' ); |
| 93 |
delete_site_option( 'spinupwp_redis_cache_disabled_notice_dismissed' ); |
| 94 |
} |
| 95 |
|
| 96 |
/** |
| 97 |
* Perform actions on admin init. |
| 98 |
*/ |
| 99 |
public function admin_init() { |
| 100 |
if ( is_plugin_active( 'redis-cache/redis-cache.php' ) ) { |
| 101 |
deactivate_plugins( 'redis-cache/redis-cache.php' ); |
| 102 |
update_site_option( 'spinupwp_redis_cache_disabled', true ); |
| 103 |
} |
| 104 |
} |
| 105 |
} |
| 106 |
|