maybe_upgrade_database(); $stored = get_option( self::VERSION_OPTION, '0' ); if ( version_compare( is_string( $stored ) ? $stored : '0', ELEVENRANK_VERSION, '>=' ) ) { return; } foreach ( $this->migrations() as $version => $migration ) { if ( version_compare( is_string( $stored ) ? $stored : '0', (string) $version, '<' ) ) { call_user_func( $migration ); } } $this->stamp_versions(); } /** * Creates or updates the custom tables when the stored schema version is older than the code's. * * Runs on its own, apart from the plugin version: a site that is new on a network where the plugin * is active has the code but not the tables. * * @since 1.0.0 * * @return void */ public function maybe_upgrade_database(): void { if ( Database::is_ready() ) { return; } Database::install(); update_option( self::DB_VERSION_OPTION, self::DB_VERSION, true ); } /** * Records the current code and schema versions. * * @since 1.0.0 * * @return void */ public function stamp_versions(): void { update_option( self::VERSION_OPTION, ELEVENRANK_VERSION ); update_option( self::DB_VERSION_OPTION, self::DB_VERSION, true ); } /** * Migrations keyed by the version that introduced them, in ascending order. * * @since 1.0.0 * * @return array */ private function migrations(): array { return array(); } }