This repository has been archived by the owner on Apr 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
uninstall.php
67 lines (59 loc) · 1.81 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
60
61
62
63
64
65
66
67
<?php
/**
* Aldolat Twitter Uninstall
*
* @since 0.0.1
* @package AldolatTwitter
*/
// Check for the 'WP_UNINSTALL_PLUGIN' constant, before executing.
if ( ! defined( 'ABSPATH' ) && ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
exit();
}
/**
* Uninstall the options and transients from the database.
*
* @since 0.0.1
* @since 0.0.3 Added removal of transients.
*/
function aldolat_twitter_uninstall() {
global $wpdb;
// Get transient created by this plugin from the database.
$transients = $wpdb->get_col(
"SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE '%aldolat-twitter-tweets%';"
);
// If there are no transient, stop the function.
if ( ! $transients ) {
return;
}
/*
* There could be more than one transients created by this plugin,
* one for every widget.
*
* $transients is always an array, returned by $wpdb->get_col().
*
* For each plugin, WordPress creates two transients:
* '_transient_aldolat-twitter-tweets-NUMBER' containing the object with information;
* '_transient_timeout_aldolat-twitter-tweets-NUMBER' containing the expiry time of the transient.
*
* When we delete a transient '_transient_aldolat-twitter-tweets-NUMBER',
* WordPress automatically deletes the '_transient_timeout_aldolat-twitter-tweets-NUMBER' also.
*
* So, for each transient we get in the following cycle,
* we do not consider the transient with 'timeout' in its name.
*/
foreach ( $transients as $transient ) {
if ( ! strpos( $transient, 'timeout' ) ) {
$transient = str_replace( '_transient_', '', $transient );
if ( get_transient( $transient ) ) {
delete_transient( $transient );
}
}
}
// Delete options from the database.
delete_option( 'widget_aldolat_twitter_widget' );
}
aldolat_twitter_uninstall();
/*
* "So long, and thanks for all the fish."
* (Douglas Adams)
*/