'ids', 'number' => 500, ) ); foreach ( $site_ids as $site_id ) { switch_to_blog( (int) $site_id ); self::activate_site(); restore_current_blog(); } return; } self::activate_site(); } /** * Install or upgrade when the stored schema is behind. Covers in-place * updates (no activation hook) and new sites on a multisite network. */ public static function maybe_install(): void { if ( (int) get_option( Database::OPTION_VERSION, 0 ) < Database::VERSION ) { self::activate_site(); } } /** * Install for a site created after network activation. * * @param \WP_Site $site New site. */ public static function on_new_site( $site ): void { if ( ! function_exists( 'is_plugin_active_for_network' ) ) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; } if ( is_plugin_active_for_network( THINROOF_BASENAME ) ) { switch_to_blog( (int) $site->blog_id ); self::activate_site(); restore_current_blog(); } } /** * Install for the current site. */ public static function activate_site(): void { $database = new Database(); $settings = new Settings(); $settings->install_defaults(); $database->maybe_upgrade(); Capabilities::add(); add_option( 'thinroof_form_secret', wp_generate_password( 64, true, true ), '', false ); ( new Calculator( $database ) )->ensure_sample(); if ( ! wp_next_scheduled( self::CRON_HOOK ) ) { wp_schedule_event( time() + HOUR_IN_SECONDS, 'daily', self::CRON_HOOK ); } set_transient( 'thinroof_activation_notice', 1, MINUTE_IN_SECONDS * 10 ); } }