shouldMigrate() ) { return; } // run the migration. $this->run(); // update the migration complete on admin_init complete, after all migrations have run. add_action( 'admin_init', [ $this, 'complete' ], 999999 ); } /** * Should we run this migration? * * @return boolean */ public function shouldMigrate(): bool { // check if we already have done this migration. return version_compare( $this->version, $this->getLastMigrationVersion(), '>=' ); } /** * Run the migration * * @return void */ protected function run() { } /** * Store the current plugin version when complete. * * @return void */ public function complete() { update_option( $this->migration_key, \SureCart::plugin()->version() ); } /** * Get the last version there was a migration. * * @return string */ public function getLastMigrationVersion() { return get_option( $this->migration_key, '0.0.0' ); } }