boot(); } return self::$instance; } /** * Boot. */ private function boot() { // Pro build only (not in the wordpress.org version): bundled translations, data folder move. if ( class_exists( '\Fehu\Autopilot\Pro\Setup' ) ) { \Fehu\Autopilot\Pro\Setup::register(); } $classes = array( '\Fehu\Autopilot\Modules\Cache', '\Fehu\Autopilot\Pro\Images', '\Fehu\Autopilot\Modules\Security', '\Fehu\Autopilot\Pro\Turnstile', '\Fehu\Autopilot\Modules\Origin', '\Fehu\Autopilot\Pro\Backups', ); foreach ( $classes as $class ) { if ( class_exists( $class ) ) { $module = new $class(); $this->modules[ $module->id() ] = $module; } } $this->modules = apply_filters( 'fehu_ap_modules', $this->modules ); if ( Site::connected() ) { foreach ( $this->modules as $module ) { $module->register(); } } ( new Rest() )->register(); if ( is_admin() ) { ( new Admin() )->register(); } add_action( 'fehu_ap_daily', array( __CLASS__, 'daily' ) ); } /** * Module by id. * * @param string $id Id. * @return Module|null */ public function module( $id ) { return isset( $this->modules[ $id ] ) ? $this->modules[ $id ] : null; } /** * All modules. * * @return Module[] */ public function modules() { return $this->modules; } /** * Daily housekeeping: health refresh (Freemius re-checks the license itself). */ public static function daily() { if ( Site::connected() ) { Health::run(); } } /** * Activation. */ public static function activate() { if ( ! wp_next_scheduled( 'fehu_ap_daily' ) ) { wp_schedule_event( time() + HOUR_IN_SECONDS, 'daily', 'fehu_ap_daily' ); } } /** * Deactivation: never leave the site locked or serving stale cached pages. */ public static function deactivate() { wp_clear_scheduled_hook( 'fehu_ap_daily' ); wp_clear_scheduled_hook( 'fehu_ap_backup_run' ); if ( class_exists( '\Fehu\Autopilot\Pro\Origin_Lock' ) ) { \Fehu\Autopilot\Pro\Origin_Lock::remove_block(); $state = Store::module( 'origin_lock' ); if ( ! empty( $state['stage'] ) && 'enforced' === $state['stage'] ) { Store::update_module( 'origin_lock', array( 'stage' => 'verified' ) ); } } // Without the plugin nobody purges changed pages, so stop edge-caching HTML. if ( Site::connected() ) { $cache = Store::module( 'cache' ); if ( ! empty( $cache['enabled'] ) ) { $res = ( new Rules() )->remove( 'http_request_cache_settings', 'page_cache' ); if ( ! is_wp_error( $res ) ) { Store::update_module( 'cache', array( 'enabled' => false ) ); Cloudflare::stored()->purge( Site::zone_id(), array( 'hosts' => Site::hosts() ) ); } } } Store::log( 'core', __( 'Plugin deactivated: origin lock removed from .htaccess, edge page cache rule removed.', 'zonepilot' ), 'info' ); } }