-
Notifications
You must be signed in to change notification settings - Fork 13
/
uninstaller.php
75 lines (61 loc) · 3.02 KB
/
uninstaller.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
/**
* Fired when the plugin is uninstalled
*
* @package Better_Search
*/
// If this file is called directly, then abort execution.
if ( ! defined( 'WPINC' ) ) {
die( "Aren't you supposed to come here via WP-Admin?" );
}
global $wpdb;
if ( is_multisite() ) {
$sites = get_sites(
array(
'archived' => 0,
'spam' => 0,
'deleted' => 0,
)
);
foreach ( $sites as $site ) {
switch_to_blog( (int) $site->blog_id );
bsearch_delete_data();
restore_current_blog();
}
} else {
bsearch_delete_data();
}
/**
* Delete plugin data.
*
* @since 2.5.0
*/
function bsearch_delete_data() {
global $wpdb;
if ( defined( 'BETTER_SEARCH_DELETE_DATA' ) && BETTER_SEARCH_DELETE_DATA ) {
$wpdb->query( 'DROP TABLE ' . $wpdb->prefix . 'bsearch' ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.SchemaChange,WordPress.DB.DirectDatabaseQuery.NoCaching,WordPress.DB.DirectDatabaseQuery.DirectQuery
$wpdb->query( 'DROP TABLE ' . $wpdb->prefix . 'bsearch_daily' ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.SchemaChange,WordPress.DB.DirectDatabaseQuery.NoCaching,WordPress.DB.DirectDatabaseQuery.DirectQuery
}
delete_option( 'ald_bsearch_settings' );
delete_option( 'bsearch_settings' );
delete_option( 'bsearch_db_version' );
$wpdb->query( 'ALTER TABLE ' . $wpdb->posts . ' DROP INDEX bsearch' ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.SchemaChange,WordPress.DB.DirectDatabaseQuery.NoCaching,WordPress.DB.DirectDatabaseQuery.DirectQuery
$wpdb->query( 'ALTER TABLE ' . $wpdb->posts . ' DROP INDEX bsearch_title' ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.SchemaChange,WordPress.DB.DirectDatabaseQuery.NoCaching,WordPress.DB.DirectDatabaseQuery.DirectQuery
$wpdb->query( 'ALTER TABLE ' . $wpdb->posts . ' DROP INDEX bsearch_content' ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.SchemaChange,WordPress.DB.DirectDatabaseQuery.NoCaching,WordPress.DB.DirectDatabaseQuery.DirectQuery
// Drop fuzzy functions.
$wpdb->query( 'DROP FUNCTION IF EXISTS wz_levenshtein' ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.SchemaChange,WordPress.DB.DirectDatabaseQuery.NoCaching,WordPress.DB.DirectDatabaseQuery.DirectQuery
$wpdb->query( 'DROP FUNCTION IF EXISTS wz_phrase_similarity_levenshtein' ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.SchemaChange,WordPress.DB.DirectDatabaseQuery.NoCaching,WordPress.DB.DirectDatabaseQuery.DirectQuery
$wpdb->query( 'DROP FUNCTION IF EXISTS wz_phrase_similarity_soundex' ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.SchemaChange,WordPress.DB.DirectDatabaseQuery.NoCaching,WordPress.DB.DirectDatabaseQuery.DirectQuery
$sql = "
SELECT option_name
FROM {$wpdb->options}
WHERE `option_name` LIKE '_transient_bs_%'
";
$results = $wpdb->get_results( $sql ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared
if ( is_array( $results ) ) {
foreach ( $results as $result ) {
$transient = str_replace( '_transient_', '', $result->option_name );
delete_transient( $transient );
}
}
}