-
Notifications
You must be signed in to change notification settings - Fork 15
/
uninstall.php
121 lines (98 loc) · 3.85 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
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
<?php
defined('ABSPATH') or exit('Please don’t call the plugin directly. Thanks :)');
/**
* Uninstall SEOPress
*
* @since 6.2
*
* @author Benjamin, inspired by Polylang
*/
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { // If uninstall not called from WordPress exit
exit;
}
class SEOPRESS_Uninstall {
/**
* Constructor: manages uninstall for multisite
*
* @since 6.2
*/
public function __construct() {
global $wpdb;
// Don't do anything except if the constant SEOPRESS_UNINSTALL is explicitely defined and true.
if ( ! defined( 'SEOPRESS_UNINSTALL' ) || ! SEOPRESS_UNINSTALL ) {
return;
}
// Check if it is a multisite uninstall - if so, run the uninstall function for each blog id
if ( is_multisite() ) {
foreach ( $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" ) as $blog_id ) {
switch_to_blog( $blog_id );
$this->uninstall();
}
restore_current_blog();
}
else {
$this->uninstall();
}
}
/**
* Delete all entries in the DB related to SEOPress Free AND PRO:
* Transients, post meta, options, custom tables
*
* @since 6.2
* @updated 7.4
*/
public function uninstall() {
global $wpdb;
do_action( 'seopress_uninstall' );
// Delete post meta
$wpdb->query( "DELETE FROM $wpdb->postmeta WHERE meta_key LIKE '_seopress_%'" );
// Delete redirections / 404 errors
$sql = 'DELETE `posts`, `pm`
FROM `' . $wpdb->prefix . 'posts` AS `posts`
LEFT JOIN `' . $wpdb->prefix . 'postmeta` AS `pm` ON `pm`.`post_id` = `posts`.`ID`
WHERE `posts`.`post_type` = \'seopress_404\'';
$sql = $wpdb->prepare($sql);
$wpdb->query($sql);
// Delete schemas
$sql = 'DELETE `posts`, `pm`
FROM `' . $wpdb->prefix . 'posts` AS `posts`
LEFT JOIN `' . $wpdb->prefix . 'postmeta` AS `pm` ON `pm`.`post_id` = `posts`.`ID`
WHERE `posts`.`post_type` = \'seopress_schemas\'';
$sql = $wpdb->prepare($sql);
$wpdb->query($sql);
// Delete broken links
$sql = 'DELETE `posts`, `pm`
FROM `' . $wpdb->prefix . 'posts` AS `posts`
LEFT JOIN `' . $wpdb->prefix . 'postmeta` AS `pm` ON `pm`.`post_id` = `posts`.`ID`
WHERE `posts`.`post_type` = \'seopress_bot\'';
$sql = $wpdb->prepare($sql);
$wpdb->query($sql);
// Delete global settings
$options = $wpdb->get_col( "SELECT option_name FROM $wpdb->options WHERE option_name LIKE 'seopress_%'" );
array_map( 'delete_option', $options );
// Delete widget options
$options = $wpdb->get_col( "SELECT option_name FROM $wpdb->options WHERE option_name LIKE 'widget_seopress_%'" );
array_map( 'delete_option', $options );
// Delete transients
delete_transient( '_seopress_sitemap_ids_video' );
delete_transient( 'seopress_results_page_speed' );
delete_transient( 'seopress_results_page_speed_desktop' );
delete_transient( 'seopress_results_google_analytics' );
delete_transient( 'seopress_results_matomo' );
delete_transient( 'seopress_prevent_title_redirection_already_exist' );
// Delete custom tables
$wpdb->query("DROP TABLE IF EXISTS {$wpdb->prefix}seopress_significant_keywords");
// Clear CRON
wp_clear_scheduled_hook('seopress_xml_sitemaps_ping_cron');
wp_clear_scheduled_hook('seopress_404_cron_cleaning');
wp_clear_scheduled_hook('seopress_google_analytics_cron');
wp_clear_scheduled_hook('seopress_page_speed_insights_cron');
wp_clear_scheduled_hook('seopress_404_email_alerts_cron');
wp_clear_scheduled_hook('seopress_insights_gsc_cron');
wp_clear_scheduled_hook('seopress_matomo_analytics_cron');
wp_clear_scheduled_hook('seopress_alerts_cron');
$wpdb->query("DROP TABLE IF EXISTS {$wpdb->prefix}seopress_content_analysis");
$wpdb->query("DROP TABLE IF EXISTS {$wpdb->prefix}seopress_seo_issues");
}
}
new SEOPRESS_Uninstall();