-
Notifications
You must be signed in to change notification settings - Fork 6
/
uninstall.php
85 lines (71 loc) · 1.47 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
/**
* Better YOURLs uninstaller
*
* Used when clicking "Delete" from inside of WordPress's plugins page.
*
* @package better-yourls
*
* @since 2.0.0
*
* @author Chris Wiegman <chris@wiegman.us>
*/
/**
* Class Better_YOURLs_Uninstaller
*/
class Better_YOURLs_Uninstaller {
/**
* Initialize uninstaller
*
* Perform some checks to make sure plugin can/should be uninstalled
*
* @since 2.0.0
*/
public function __construct() {
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
$this->exit_uninstaller();
}
// Not uninstalling.
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
$this->exit_uninstaller();
}
// Not uninstalling.
if ( ! WP_UNINSTALL_PLUGIN ) {
$this->exit_uninstaller();
}
// Not uninstalling this plugin.
if ( dirname( WP_UNINSTALL_PLUGIN ) !== dirname( plugin_basename( __FILE__ ) ) ) {
$this->exit_uninstaller();
}
// Uninstall Better YOURLs.
self::clean_data();
}
/**
* Cleanup options
*
* Deletes Better YOURLs' options and post_meta.
*
* @since 2.0.0
*
* @return void
*/
protected static function clean_data() {
delete_option( 'better_yourls' );
delete_metadata( 'post', null, '_better_yourls_short_link', null, true );
}
/**
* Exit uninstaller
*
* Gracefully exit the uninstaller if we should not be here
*
* @since 2.0.0
*
* @return void
*/
protected function exit_uninstaller() {
status_header( 404 );
exit;
}
}
new Better_YOURLs_Uninstaller();