'ids', 'number' => self::NETWORK_INLINE_SITES, ) ); foreach ( $site_ids as $site_id ) { switch_to_blog( (int) $site_id ); self::activate_site(); restore_current_blog(); } return; } self::activate_site(); } /** * Install tables for the current site and request a full scan. */ public static function activate_site(): void { self::maybe_update_schema(); self::ensure_options(); update_option( self::FULL_SCAN_FLAG, 1, true ); update_option( self::NOTICE_FLAG, 1, true ); } /** * Runs on every load (cheap: autoloaded option). Installs tables lazily, e.g. for new network sites. */ public static function maybe_update_schema(): void { $installed = (int) get_option( Schema::OPTION, 0 ); if ( Schema::VERSION === $installed ) { return; } Schema::install( $installed ); self::ensure_options(); if ( 0 === $installed ) { update_option( self::FULL_SCAN_FLAG, 1, true ); } } /** * Create every option that front-end requests may read, autoloaded. A missing option costs one * query per page view (WordPress caches only existing autoloaded options). */ public static function ensure_options(): void { add_option( self::FULL_SCAN_FLAG, 0, '', true ); add_option( \Unbreak\Check\CheckRunner::PAUSED, 0, '', true ); add_option( \Unbreak\Support\Settings::OPTION, \Unbreak\Support\Settings::sanitize( \Unbreak\Support\Settings::defaults() ), '', true ); } /** * Deactivation hook: stop all background work, keep data (uninstall removes it). * * @param bool $network_wide Whether the plugin is being network-deactivated. */ public static function deactivate( $network_wide = false ): void { if ( is_multisite() && $network_wide ) { $site_ids = get_sites( array( 'fields' => 'ids', 'number' => 0, ) ); foreach ( $site_ids as $site_id ) { switch_to_blog( (int) $site_id ); self::deactivate_site(); restore_current_blog(); } return; } self::deactivate_site(); } /** * Unschedule our jobs on the current site. */ private static function deactivate_site(): void { if ( function_exists( 'as_unschedule_all_actions' ) ) { as_unschedule_all_actions( '', array(), Jobs::GROUP ); } delete_transient( 'unbreak_redirect_map_always' ); delete_transient( 'unbreak_redirect_map_404' ); } }