google-site-kit
Last commit date
bin
6 years ago
dist
6 years ago
includes
6 years ago
third-party
6 years ago
google-site-kit.php
6 years ago
readme.txt
6 years ago
uninstall.php
6 years ago
uninstall.php
68 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Plugin reset and uninstall cleanup. |
| 4 | * |
| 5 | * @package Google\Site_Kit |
| 6 | * @copyright 2019 Google LLC |
| 7 | * @license https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0 |
| 8 | * @link https://sitekit.withgoogle.com |
| 9 | */ |
| 10 | |
| 11 | namespace Google\Site_Kit; |
| 12 | |
| 13 | // Bail if not uninstalling or resetting the plugin. |
| 14 | if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) && empty( $googlesitekit_reset_context ) ) { |
| 15 | return; |
| 16 | } |
| 17 | |
| 18 | global $wpdb; |
| 19 | |
| 20 | $prefix = 'googlesitekit\_%'; |
| 21 | |
| 22 | // Delete options and transients. |
| 23 | $wpdb->query( // phpcs:ignore WordPress.VIP.DirectDatabaseQuery |
| 24 | $wpdb->prepare( |
| 25 | "DELETE FROM $wpdb->options WHERE option_name LIKE %s OR option_name LIKE %s OR option_name LIKE %s OR option_name = %s", |
| 26 | $prefix, |
| 27 | '_transient_' . $prefix, |
| 28 | '_transient_timeout_' . $prefix, |
| 29 | 'googlesitekit-active-modules' |
| 30 | ) |
| 31 | ); |
| 32 | |
| 33 | // Delete user meta. |
| 34 | $wpdb->query( // phpcs:ignore WordPress.VIP.DirectDatabaseQuery |
| 35 | $wpdb->prepare( "DELETE FROM $wpdb->usermeta WHERE meta_key LIKE %s", $wpdb->get_blog_prefix() . $prefix ) |
| 36 | ); |
| 37 | |
| 38 | // Clear network data if multisite and uninstalling or resetting network-wide. |
| 39 | $conditions = ( |
| 40 | is_multisite() |
| 41 | && |
| 42 | ( |
| 43 | defined( 'WP_UNINSTALL_PLUGIN' ) |
| 44 | || |
| 45 | ( ! empty( $googlesitekit_reset_context ) && $googlesitekit_reset_context->is_network_mode() ) |
| 46 | ) |
| 47 | ); |
| 48 | |
| 49 | if ( $conditions ) { |
| 50 | $wpdb->query( // phpcs:ignore WordPress.VIP.DirectDatabaseQuery |
| 51 | $wpdb->prepare( |
| 52 | "DELETE FROM $wpdb->sitemeta WHERE meta_key LIKE %s OR meta_key LIKE %s OR meta_key LIKE %s OR meta_key = %s", |
| 53 | $prefix, |
| 54 | '_site_transient_' . $prefix, |
| 55 | '_site_transient_timeout_' . $prefix, |
| 56 | 'googlesitekit-active-modules' |
| 57 | ) |
| 58 | ); |
| 59 | |
| 60 | // Delete user meta. |
| 61 | $wpdb->query( // phpcs:ignore WordPress.VIP.DirectDatabaseQuery |
| 62 | $wpdb->prepare( "DELETE FROM $wpdb->usermeta WHERE meta_key LIKE %s", $prefix ) |
| 63 | ); |
| 64 | } |
| 65 | |
| 66 | // Clear options cache. |
| 67 | wp_cache_flush(); |
| 68 |