-
Notifications
You must be signed in to change notification settings - Fork 30
/
uninstall.php
executable file
·59 lines (54 loc) · 1.96 KB
/
uninstall.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
<?php
if ( ! defined( 'ABSPATH' ) && ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
die();
}
/**
* Contains uninstall routines to clean up plugin data on deletion.
*/
function idx_delete_plugin_data() {
// Delete the assigned dynamic wrapper page ID. Legacy - we remove all idx-wrapper posts later.
$page_id = get_option( 'idx_broker_dynamic_wrapper_page_id' );
if ( $page_id ) {
wp_delete_post( $page_id, true );
}
global $wpdb;
// Delete pseudo-transients.
$wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->options WHERE option_name LIKE %s", '%idx_%_cache' ) );
// Delete omnibar data.
$wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->options WHERE option_name LIKE %s", '%idx_omnibar%' ) );
// Delete middleware widgets.
$wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->options WHERE option_name LIKE %s", '%widget_idx%' ) );
// Delete dismissed notices.
$wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->options WHERE option_name LIKE %s", '%idx-notice-dismissed%' ) );
// Delete any other idx_ prefixed options. *Excludes API key.
$wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->options WHERE option_name LIKE %s AND option_name NOT LIKE %s", 'idx_%', 'idx_broker_apikey' ) );
// Delete the autocomplete table (new rest api autcomplete).
$autocomplete_table_name = $wpdb->prefix . 'idx_broker_autocomplete_values';
$wpdb->query( "DROP TABLE IF EXISTS $autocomplete_table_name" );
// Delete all IDX page posts.
$idx_pages = get_posts(
array(
'post_type' => 'idx_page',
'numberposts' => -1,
'post_status' => 'any',
)
);
foreach ( $idx_pages as $post ) {
wp_delete_post( $post->ID, true );
}
// Delete all wrapper posts.
$idx_wrappers = get_posts(
array(
'post_type' => 'idx-wrapper',
'numberposts' => -1,
)
);
foreach ( $idx_wrappers as $post ) {
wp_delete_post( $post->ID, true );
}
}
// Run cleanup method.
idx_delete_plugin_data();
if ( ! is_plugin_active( 'wp-listings/plugin.php' ) ) {
include_once 'add-ons/listings/uninstall.php';
}