-
-
Notifications
You must be signed in to change notification settings - Fork 70
/
uninstall.php
executable file
·88 lines (75 loc) · 1.88 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
86
87
88
<?php
/**
* Uninstall Ajax Load More
*
* Deletes all the plugin data.
* 1. Custom Tables.
* 2. Repeater Templates.
* 3. Cache Directory.
*
* @since 4.1
* @package AjaxLoadMore
*/
// Exit if accessed directly.
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
exit;
}
require_once 'ajax-load-more.php';
global $wpdb;
if ( is_multisite() ) {
// Multisite.
$blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
foreach ( $blog_ids as $blog_id ) {
switch_to_blog( $blog_id );
$alm_options = get_option( 'alm_settings' );
if ( isset( $alm_options['_alm_uninstall'] ) ) {
if ( 1 === $alm_options['_alm_uninstall'] ) {
alm_delete_templates();
alm_drop_table();
delete_option( 'alm_settings' ); // Delete settings.
}
}
restore_current_blog();
}
} else {
// Standard.
$alm_options = get_option( 'alm_settings' );
if ( isset( $alm_options['_alm_uninstall'] ) ) {
if ( 1 === $alm_options['_alm_uninstall'] ) {
alm_delete_templates();
alm_drop_table();
delete_option( 'alm_settings' ); // Delete settings.
}
}
}
/**
* Delete all ALM tables
*/
function alm_delete_templates() {
// Exit if `alm_repeater_path` has been modified outside of the plugin.
// We don't want to delete a directory in a theme so let's skip this.
if ( has_filter( 'alm_repeater_path' ) ) {
return false;
}
$dir = AjaxLoadMore::alm_get_repeater_path(); // /alm_templates directory
if ( ! is_dir( $dir ) ) {
return; // Confirm directory exists.
}
// Loop all files in directory.
foreach ( glob( $dir . '/*.*' ) as $filename ) {
// Delete files.
if ( is_file( $filename ) ) {
unlink( $filename );
}
}
// Remove directory.
rmdir( $dir );
}
/**
* Delete all ALM tables
*/
function alm_drop_table() {
global $wpdb;
$wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'alm' );
$wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'alm_unlimited' );
}