PluginProbe
Performance Lab / 1.8.0
Performance Lab v1.8.0
trunk 1.0.0 1.0.0-beta.1 1.0.0-beta.2 1.0.0-beta.3 1.0.0-rc.1 1.1.0 1.2.0 1.3.0 1.4.0 1.5.0 1.6.0 1.7.0 1.8.0 1.9.0 2.0.0 2.1.0 2.2.0 2.3.0 2.4.0 2.5.0 2.6.0 2.6.1 2.7.0 2.8.0 All 44 releases
performance-lab / modules / database / sqlite / deactivate.php

deactivate.php in Performance Lab 1.8.0, at modules/database/sqlite/deactivate.php

56 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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