Skip to content

Commit 189322a

Browse files
authored
Restore database version support for older WordPress releases (#484)
## Summary Restore `WP_SQLite_DB::db_version()` and remove the redundant implementation from the unit-test `wpdb` stub. ## Why WordPress 5.4 and older do not provide `wpdb::db_server_info()`. Their inherited `db_version()` asks the MySQL extension for server information directly, which does not work with the SQLite-backed connection used by Playground. Defining the method on the drop-in makes these releases read the emulated MySQL version through the driver API. Fixes WordPress/wordpress-playground#4256
1 parent 8767a36 commit 189322a

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

‎packages/mysql-on-sqlite/tests/fixtures/class-wpdb-stub.php‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@ class WPDB_Stub {
44
public function add_placeholder_escape( $query ) {
55
return $query;
66
}
7-
8-
public function db_version() {
9-
return preg_replace( '/[^0-9.].*/', '', $this->db_server_info() );
10-
}
117
}
128

139
class_alias( WPDB_Stub::class, 'wpdb' );

‎packages/plugin-sqlite-database-integration/wp-includes/sqlite/class-wp-sqlite-db.php‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,21 @@ public function has_cap( $db_cap ) {
745745
return parent::has_cap( $db_cap );
746746
}
747747

748+
/**
749+
* Retrieves the emulated database server version number.
750+
*
751+
* This mirrors wpdb::db_version(), but must also be defined here because
752+
* WordPress 5.4 and older fetch server information directly from the MySQL
753+
* extension instead of delegating to wpdb::db_server_info().
754+
*
755+
* @see wpdb::db_version()
756+
*
757+
* @return string Version number on success, or an empty string while disconnected.
758+
*/
759+
public function db_version() {
760+
return preg_replace( '/[^0-9.].*/', '', $this->db_server_info() );
761+
}
762+
748763
/**
749764
* Returns the raw version string of the emulated MySQL server.
750765
*

0 commit comments

Comments
 (0)