PluginProbe
SQLite Database Integration / 2.2.13
SQLite Database Integration v2.2.13
3.0.1 trunk 2.1.13 2.1.14 2.1.15 2.1.16 2.2.0 2.2.1 2.2.10 2.2.11 2.2.12 2.2.13 2.2.14 2.2.15 2.2.16 2.2.17 2.2.18 2.2.19 2.2.2 2.2.20 2.2.21 2.2.22 2.2.23 2.2.3 2.2.4 All 31 releases
sqlite-database-integration / deactivate.php

deactivate.php in SQLite Database Integration 2.2.13, at deactivate.php

69 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Handle the SQLite deactivation.
4 *
5 * @since 1.0.0
6 * @package wp-sqlite-integration
7 */
8
9 /**
10 * Delete the db.php file in wp-content.
11 *
12 * When the plugin gets merged in wp-core, this is not to be ported.
13 */
14 function sqlite_plugin_remove_db_file() {
15 if ( ! defined( '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 // Flush any persistent cache.
26 wp_cache_flush();
27 // Delete the drop-in.
28 $wp_filesystem->delete( WP_CONTENT_DIR . '/db.php' );
29 // Flush the cache again to mitigate a possible race condition.
30 wp_cache_flush();
31 }
32
33 // Run an action on `shutdown`, to deactivate the option in the MySQL database.
34 add_action(
35 'shutdown',
36 function () {
37 global $table_prefix;
38
39 // Get credentials for the MySQL database.
40 $dbuser = defined( 'DB_USER' ) ? DB_USER : '';
41 $dbpassword = defined( 'DB_PASSWORD' ) ? DB_PASSWORD : '';
42 $dbname = defined( 'DB_NAME' ) ? DB_NAME : '';
43 $dbhost = defined( 'DB_HOST' ) ? DB_HOST : '';
44
45 // Init a connection to the MySQL database.
46 $wpdb_mysql = new wpdb( $dbuser, $dbpassword, $dbname, $dbhost );
47 $wpdb_mysql->set_prefix( $table_prefix );
48
49 // Get the perflab options, remove the database/sqlite module and update the option.
50 $row = $wpdb_mysql->get_row( $wpdb_mysql->prepare( "SELECT option_value FROM $wpdb_mysql->options WHERE option_name = %s LIMIT 1", 'active_plugins' ) );
51 if ( is_object( $row ) ) {
52 $value = maybe_unserialize( $row->option_value );
53 if ( is_array( $value ) ) {
54 $value_flipped = array_flip( $value );
55 $items = array_reverse( explode( DIRECTORY_SEPARATOR, SQLITE_MAIN_FILE ) );
56 $item = $items[1] . DIRECTORY_SEPARATOR . $items[0];
57 unset( $value_flipped[ $item ] );
58 $value = array_flip( $value_flipped );
59 $wpdb_mysql->update( $wpdb_mysql->options, array( 'option_value' => maybe_serialize( $value ) ), array( 'option_name' => 'active_plugins' ) );
60 }
61 }
62 },
63 PHP_INT_MAX
64 );
65 // Flush any persistent cache.
66 wp_cache_flush();
67 }
68 register_deactivation_hook( SQLITE_MAIN_FILE, 'sqlite_plugin_remove_db_file' ); // Remove db.php file on plugin deactivation.
69