1313
1414define( 'SQLITE_DB_DROPIN_VERSION', '1.8.0' );
1515
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+
1622// 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;
2725}
2826
2927// Constant for backward compatibility.
@@ -36,23 +34,24 @@ if ( ! defined( 'DB_ENGINE' ) ) {
3634}
3735
3836// 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' ;
4038
4139// Activate the performance-lab plugin if it is not already activated.
4240add_action(
4341 'admin_footer',
44- function() use ( $sqlite_db_plugin_main_file ) {
42+ function() {
4543 if ( defined( 'SQLITE_MAIN_FILE' ) ) {
4644 return;
4745 }
4846 if ( ! function_exists( 'activate_plugin' ) ) {
4947 require_once ABSPATH . 'wp-admin/includes/plugin.php';
5048 }
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 );
5655 }
5756 }
5857 }
0 commit comments