' ) ) { throw new \InvalidArgumentException( 'Invalid database version provided for upgrade.' ); } $this->db_version = $db_version; } /** * Performs the upgrade routine. * * @since 0.6.0 * * @return true|\WP_Error True on success, or a WP_Error on failure. */ public function run() { if ( version_compare( $this->db_version, static::$version, '>=' ) ) { // No upgrade needed. return true; } try { $this->upgrade(); } catch ( \Throwable $e ) { return new \WP_Error( 'wpai_upgrade_failed', $e->getMessage() ); } return true; } /** * The upgrade process. * * @throws \Exception Throws an exception if the upgrade fails. */ abstract protected function upgrade(): void; }