13
13
14
14
define( 'SQLITE_DB_DROPIN_VERSION', '1.8.0' );
15
15
16
+ // Tweak to allow copy-pasting the file without having to run string-replacements.
17
+ $sqlite_plugin_implementation_folder_path = '{SQLITE_IMPLEMENTATION_FOLDER_PATH}';
18
+ if ( ! file_exists( $sqlite_plugin_implementation_folder_path ) ) { // Check that the folder exists.
19
+ $sqlite_plugin_implementation_folder_path = realpath( __DIR__ . '/plugins/sqlite-database-integration' );
20
+ }
21
+
16
22
// Bail early if the SQLite implementation was not located in the plugin.
17
- $sqlite_db_plugin_folder = '{SQLITE_IMPLEMENTATION_FOLDER_PATH}';
18
- $sqlite_db_plugin_db_file = $sqlite_db_plugin_folder . '/wp-includes/sqlite/db.php';
19
- $sqlite_db_plugin_main_file = WP_PLUGIN_DIR . '/{SQLITE_PLUGIN}';
20
- if ( ! file_exists( $sqlite_db_plugin_db_file ) ) {
21
- $sqlite_db_plugin_folder = WP_PLUGIN_DIR . '/sqlite-database-integration';
22
- $sqlite_db_plugin_db_file = $sqlite_db_plugin_folder . '/wp-includes/sqlite/db.php';
23
- $sqlite_db_plugin_main_file = $sqlite_db_plugin_folder . '/load.php';
24
- if ( ! file_exists( $sqlite_db_plugin_db_file ) ) {
25
- return;
26
- }
23
+ if ( ! $sqlite_plugin_implementation_folder_path || ! file_exists( $sqlite_plugin_implementation_folder_path . '/wp-includes/sqlite/db.php' ) ) {
24
+ return;
27
25
}
28
26
29
27
// Constant for backward compatibility.
@@ -36,23 +34,24 @@ if ( ! defined( 'DB_ENGINE' ) ) {
36
34
}
37
35
38
36
// Require the implementation from the plugin.
39
- require_once $sqlite_db_plugin_db_file ;
37
+ require_once $sqlite_plugin_implementation_folder_path . '/wp-includes/sqlite/db.php' ;
40
38
41
39
// Activate the performance-lab plugin if it is not already activated.
42
40
add_action(
43
41
'admin_footer',
44
- function() use ( $sqlite_db_plugin_main_file ) {
42
+ function() {
45
43
if ( defined( 'SQLITE_MAIN_FILE' ) ) {
46
44
return;
47
45
}
48
46
if ( ! function_exists( 'activate_plugin' ) ) {
49
47
require_once ABSPATH . 'wp-admin/includes/plugin.php';
50
48
}
51
-
52
- if ( file_exists( $sqlite_db_plugin_main_file ) ) {
53
- $plugin_file = str_replace( WP_PLUGIN_DIR . '/', '', $sqlite_db_plugin_main_file );
54
- if ( is_plugin_inactive( $plugin_file ) ) {
55
- activate_plugin( $plugin_file );
49
+ if ( is_plugin_inactive( '{SQLITE_PLUGIN}' ) ) {
50
+ // If `activate_plugin()` returns a value other than null (like WP_Error),
51
+ // the plugin could not be found. Try with a hardcoded string,
52
+ // because that probably means the file was directly copy-pasted.
53
+ if ( null !== activate_plugin( '{SQLITE_PLUGIN}', '', false, true ) ) {
54
+ activate_plugin( 'sqlite-database-integration/load.php', '', false, true );
56
55
}
57
56
}
58
57
}
0 commit comments