@@ -28,13 +28,8 @@ function sqlite_plugin_get_database_location_warning() {
2828 * @return string Location status: public, outside, memory, or unknown.
2929 */
3030function sqlite_plugin_get_database_location_status () {
31- // The drop-in loads the storage only after SQLite is set up.
32- if ( ! class_exists ( 'WP_SQLite_Storage ' , false ) ) {
33- require_once __DIR__ . '/wp-includes/sqlite/class-wp-sqlite-storage.php ' ;
34- }
35-
3631 list ( $ path , $ is_secret_root ) = sqlite_plugin_get_database_location ();
37- if ( ! sqlite_plugin_is_valid_database_location ( $ path , $ is_secret_root ) ) {
32+ if ( null === sqlite_plugin_get_database_storage ( $ path , $ is_secret_root ) ) {
3833 return 'unknown ' ;
3934 }
4035 if ( ':memory: ' === $ path ) {
@@ -80,14 +75,14 @@ function sqlite_plugin_get_database_location_status() {
8075}
8176
8277/**
83- * Read the active path, or the planned legacy/default location before setup .
78+ * Check whether the drop-in can create and write the database at the configured location .
8479 *
8580 * @access private
86- * @return mixed Configured path, which may be invalid .
81+ * @return bool Whether the location is valid and writable .
8782 */
88- function sqlite_plugin_get_database_path () {
89- list ( $ path ) = sqlite_plugin_get_database_location ();
90- return $ path ;
83+ function sqlite_plugin_is_database_location_writable () {
84+ $ storage = sqlite_plugin_get_database_storage ( ... sqlite_plugin_get_database_location () );
85+ return null !== $ storage && $ storage -> is_writable () ;
9186}
9287
9388/**
@@ -121,27 +116,27 @@ function sqlite_plugin_get_database_location() {
121116}
122117
123118/**
124- * Check whether the drop-in accepts a database location.
119+ * Create a storage manager for a location without initializing the storage .
125120 *
126121 * @access private
127122 * @param mixed $path Configured path.
128123 * @param bool $is_secret_root Whether the path is the directory of a secret path.
129- * @return bool Whether the drop-in can use the location.
124+ * @return WP_SQLite_Storage|null Storage manager, or null when the drop-in rejects the location.
130125 */
131- function sqlite_plugin_is_valid_database_location ( $ path , $ is_secret_root ) {
126+ function sqlite_plugin_get_database_storage ( $ path , $ is_secret_root ) {
132127 if ( ! is_string ( $ path ) ) {
133- return false ;
128+ return null ;
129+ }
130+
131+ // The drop-in loads the storage only after SQLite is set up.
132+ if ( ! class_exists ( 'WP_SQLite_Storage ' , false ) ) {
133+ require_once __DIR__ . '/wp-includes/sqlite/class-wp-sqlite-storage.php ' ;
134134 }
135135 try {
136- if ( $ is_secret_root ) {
137- WP_SQLite_Storage ::with_secret_path ( $ path );
138- } else {
139- WP_SQLite_Storage ::with_explicit_path ( $ path );
140- }
136+ return $ is_secret_root ? WP_SQLite_Storage ::with_secret_path ( $ path ) : WP_SQLite_Storage ::with_explicit_path ( $ path );
141137 } catch ( RuntimeException $ exception ) {
142- return false ;
138+ return null ;
143139 }
144- return true ;
145140}
146141
147142/**
0 commit comments