Skip to content

Commit fa030be

Browse files
committed
deactivate plugin in mysql db from sqlite
1 parent b8d04a8 commit fa030be

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

deactivate.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,35 @@ function sqlite_plugin_remove_db_file() {
2424
if ( $wp_filesystem || WP_Filesystem() ) {
2525
$wp_filesystem->delete( WP_CONTENT_DIR . '/db.php' );
2626
}
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", 'active_plugins' ) );
46+
if ( is_object( $row ) ) {
47+
$value = maybe_unserialize( $row->option_value );
48+
if ( is_array( $value ) ) {
49+
$value_flipped = array_flip( $value );
50+
unset( $value_flipped[ str_replace( WP_PLUGIN_DIR . '/', '', SQLITE_MAIN_FILE ) ] );
51+
$value = array_flip( $value_flipped );
52+
$wpdb_mysql->update( $wpdb_mysql->options, array( 'option_value' => maybe_serialize( $value ) ), array( 'option_name' => 'active_plugins' ) );
53+
}
54+
}
55+
}
56+
);
2757
}
2858
register_deactivation_hook( SQLITE_MAIN_FILE, 'sqlite_plugin_remove_db_file' ); // Remove db.php file on plugin deactivation.

0 commit comments

Comments
 (0)