boot(); } if ( defined( 'WP_CLI' ) && WP_CLI ) { Cli::register( new Cli( self::connect(), self::connection() ) ); \WP_CLI::add_command( 'showfm migrate-embeds', new Migration_Cli( new Migrator( self::connection(), self::api_client() ) ) ); } } /** * Registers the settings screen's REST routes. */ public static function register_admin_routes(): void { $status = new Admin_Status( self::connection() ); ( new Admin_Endpoint( self::connect(), $status ) )->register(); ( new Publishing_Endpoint( self::connection() ) )->register(); ( new Migrate_Endpoint( new Migration_Admin( new Migrator( self::connection(), self::api_client() ) ) ) )->register(); } /** * Activation. Stores the cache version and nothing else: no requests, no scheduled events. */ public static function activate(): void { Cache::ensure_version(); } /** * Deactivation only unschedules events. Settings and the connection stay until uninstall. * * @param bool $network_wide Whether the plugin is being deactivated for the network. */ public static function deactivate( bool $network_wide = false ): void { if ( ! $network_wide || ! is_multisite() ) { self::unschedule_events(); return; } $offset = 0; do { $site_ids = get_sites( array( 'network_id' => get_current_network_id(), 'fields' => 'ids', 'number' => self::SITES_PER_BATCH, 'offset' => $offset, ) ); foreach ( $site_ids as $site_id ) { switch_to_blog( (int) $site_id ); try { self::unschedule_events(); } finally { restore_current_blog(); } } $offset += self::SITES_PER_BATCH; $batch_size = count( $site_ids ); } while ( self::SITES_PER_BATCH === $batch_size ); } /** * Removes the plugin's scheduled events on the current site. */ public static function unschedule_events(): void { foreach ( self::CRON_HOOKS as $hook ) { wp_unschedule_hook( $hook ); } } /** * The connection store. */ public static function connection(): Connection { if ( null === self::$connection ) { self::$connection = new Connection(); } return self::$connection; } /** * The API client. */ public static function api_client(): Api_Client { if ( null === self::$api_client ) { self::$api_client = new Api_Client( self::connection() ); } return self::$api_client; } /** * The cache. */ public static function cache(): Cache { if ( null === self::$cache ) { self::$cache = new Cache( self::api_client() ); } return self::$cache; } /** * The connect service. */ public static function connect(): Connect { if ( null === self::$connect ) { self::$connect = new Connect( self::connection(), self::api_client() ); } return self::$connect; } /** * The health reporter. */ public static function health(): Health { if ( null === self::$health ) { self::$health = new Health( self::connection(), self::api_client(), self::connect() ); } return self::$health; } /** * Drops the shared instances. Used by tests. */ public static function reset(): void { self::$connection = null; self::$api_client = null; self::$cache = null; self::$connect = null; self::$health = null; } }