| 1 |
<?php |
| 2 |
/** |
| 3 |
* Actions to run when the module gets deactivated. |
| 4 |
* |
| 5 |
* @since 1.8.0 |
| 6 |
* @package performance-lab |
| 7 |
*/ |
| 8 |
|
| 9 |
/** |
| 10 |
* Deletes the db.php file, and deactivates the module in the SQLite database. |
| 11 |
* |
| 12 |
* @since 1.8.0 |
| 13 |
*/ |
| 14 |
return function() { |
| 15 |
if ( ! defined( 'PERFLAB_SQLITE_DB_DROPIN_VERSION' ) || ! file_exists( WP_CONTENT_DIR . '/db.php' ) ) { |
| 16 |
return; |
| 17 |
} |
| 18 |
|
| 19 |
global $wp_filesystem; |
| 20 |
|
| 21 |
require_once ABSPATH . '/wp-admin/includes/file.php'; |
| 22 |
|
| 23 |
// Init the filesystem if needed, then delete custom drop-in. |
| 24 |
if ( $wp_filesystem || WP_Filesystem() ) { |
| 25 |
$wp_filesystem->delete( WP_CONTENT_DIR . '/db.php' ); |
| 26 |
} |
| 27 |
|
| 28 |
// Run an action on `shutdown`, to deactivate the option in the MySQL database. |
| 29 |
add_action( |
| 30 |
'shutdown', |
| 31 |
function() { |
| 32 |
global $table_prefix; |
| 33 |
|
| 34 |
// Get credentials for the MySQL database. |
| 35 |
$dbuser = defined( 'DB_USER' ) ? DB_USER : ''; |
| 36 |
$dbpassword = defined( 'DB_PASSWORD' ) ? DB_PASSWORD : ''; |
| 37 |
$dbname = defined( 'DB_NAME' ) ? DB_NAME : ''; |
| 38 |
$dbhost = defined( 'DB_HOST' ) ? DB_HOST : ''; |
| 39 |
|
| 40 |
// Init a connection to the MySQL database. |
| 41 |
$wpdb_mysql = new wpdb( $dbuser, $dbpassword, $dbname, $dbhost ); |
| 42 |
$wpdb_mysql->set_prefix( $table_prefix ); |
| 43 |
|
| 44 |
// Get the perflab options, remove the database/sqlite module and update the option. |
| 45 |
$row = $wpdb_mysql->get_row( $wpdb_mysql->prepare( "SELECT option_value FROM $wpdb_mysql->options WHERE option_name = %s LIMIT 1", PERFLAB_MODULES_SETTING ) ); |
| 46 |
if ( is_object( $row ) ) { |
| 47 |
$value = maybe_unserialize( $row->option_value ); |
| 48 |
if ( is_array( $value ) && isset( $value['database/sqlite'] ) ) { |
| 49 |
unset( $value['database/sqlite'] ); |
| 50 |
$wpdb_mysql->update( $wpdb_mysql->options, array( 'option_value' => maybe_serialize( $value ) ), array( 'option_name' => PERFLAB_MODULES_SETTING ) ); |
| 51 |
} |
| 52 |
} |
| 53 |
} |
| 54 |
); |
| 55 |
}; |
| 56 |
|