-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathuninstaller.php
More file actions
151 lines (124 loc) · 4.08 KB
/
Copy pathuninstaller.php
File metadata and controls
151 lines (124 loc) · 4.08 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<?php
/**
* Fired when the plugin is uninstalled
*
* @package Contextual_Related_Posts
*/
use WebberZone\Contextual_Related_Posts\Admin\Db;
defined( 'ABSPATH' ) || exit;
if ( ! ( defined( 'WP_UNINSTALL_PLUGIN' ) || defined( 'WP_FS__UNINSTALL_MODE' ) ) ) {
exit;
}
if ( is_multisite() ) {
$sites = get_sites(
array(
'archived' => 0,
'spam' => 0,
'deleted' => 0,
)
);
foreach ( $sites as $site ) {
switch_to_blog( (int) $site->blog_id );
crp_delete_data();
restore_current_blog();
}
} else {
crp_delete_data();
}
/**
* Delete plugin data.
*
* @since 2.6.1
*/
function crp_delete_data() {
global $wpdb;
$settings = get_option( 'crp_settings' );
if ( ! empty( $settings['uninstall_options'] ) ) {
// Delete main plugin options.
delete_option( 'ald_crp_settings' );
delete_option( 'crp_settings' );
// Delete wizard-related options.
delete_option( 'crp_wizard_completed' );
delete_option( 'crp_wizard_completed_date' );
delete_option( 'crp_wizard_current_step' );
delete_option( 'crp_show_wizard' );
// Delete custom tables options.
delete_option( 'wz_posts_custom_tables_ready' );
// Delete block settings.
delete_option( 'crp_related_posts_pro_blocks_settings' );
// Delete other options set by the plugin.
delete_option( 'crp_meta_migration_done' );
// Delete post meta data.
$wpdb->query( // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.DirectDatabaseQuery.SchemaChange
"
DELETE FROM {$wpdb->postmeta}
WHERE `meta_key` LIKE 'crp_related_posts%'
OR `meta_key` LIKE '_crp%'
OR `meta_key` LIKE 'crp_post_meta%'
"
);
// Delete all plugin transients.
crp_delete_transients();
}
if ( ! empty( $settings['uninstall_indices'] ) ) {
Db::delete_fulltext_indexes();
delete_option( 'crp_db_version' );
}
if ( ! empty( $settings['uninstall_tables'] ) && class_exists( 'WebberZone\\Contextual_Related_Posts\\Pro\\Custom_Tables\\Table_Manager' ) ) {
$table_manager = new \WebberZone\Contextual_Related_Posts\Pro\Custom_Tables\Table_Manager();
$table_manager->drop_tables();
delete_option( \WebberZone\Contextual_Related_Posts\Pro\Custom_Tables\Table_Manager::$db_version_option );
}
do_action( 'crp_delete_data' );
}
/**
* Delete all plugin transients.
*
* @since 4.1.0
*/
function crp_delete_transients() {
global $wpdb;
// Delete specific known transients.
delete_transient( 'crp_reindex_state' );
delete_transient( 'crp_show_wizard_activation_redirect' );
delete_transient( 'crp_deactivated_notice_id' );
delete_transient( 'crp_reindex_scheduled' );
// Delete all transients with crp_ prefix.
$sql = "
SELECT option_name
FROM {$wpdb->options}
WHERE `option_name` LIKE '_transient_crp_%'
OR `option_name` LIKE '_transient_timeout_crp_%'
";
$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 ) {
if ( strpos( $result->option_name, '_transient_timeout_' ) === 0 ) {
// Skip timeout options, they'll be deleted with the transient.
continue;
}
$transient = str_replace( '_transient_', '', $result->option_name );
delete_transient( $transient );
}
}
// Delete site transients with crp_ prefix (for multisite).
if ( is_multisite() ) {
$sql = "
SELECT meta_key
FROM {$wpdb->sitemeta}
WHERE `meta_key` LIKE '_site_transient_crp_%'
OR `meta_key` LIKE '_site_transient_timeout_crp_%'
";
$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 ) {
if ( strpos( $result->meta_key, '_site_transient_timeout_' ) === 0 ) {
// Skip timeout options, they'll be deleted with the transient.
continue;
}
$transient = str_replace( '_site_transient_', '', $result->meta_key );
delete_site_transient( $transient );
}
}
}
}