PluginProbe
WP-EMail / trunk
WP-EMail vtrunk
3.0.0 trunk 1.00 2.00b 2.01 2.02 2.03 2.04 2.04a 2.05 2.06 2.07 2.10 2.11 2.20 2.30 2.31 2.40 2.50 2.51 2.52 2.61 2.62 2.63 2.64 All 42 releases
wp-email / uninstall.php

uninstall.php in WP-EMail trunk, at uninstall.php

116 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Uninstall WP-EMail.
4 *
5 * Runs with the plugin inactive, so nothing here may assume the plugin has
6 * booted. The three class files it needs are required explicitly and declare
7 * nothing but a class, which is also what keeps the table work -- and the
8 * query that finds the flood records, whose names are hashes -- inside
9 * includes/ where the rest of the plugin's schema lives.
10 *
11 * @package WP-EMail
12 */
13
14 defined( 'WP_UNINSTALL_PLUGIN' ) || exit;
15
16 require_once __DIR__ . '/includes/class-wp-email-admin.php';
17 require_once __DIR__ . '/includes/class-wp-email-logs.php';
18 require_once __DIR__ . '/includes/class-wp-email-form.php';
19
20 /**
21 * Delete the plugin's options for the current site.
22 *
23 * The list is longer than the plugin now writes: 3.0.0 folded eighteen rows
24 * into wp_email_options and wp_email_version, but an install that never reached
25 * the migration still has the originals, and uninstall has to clear those too.
26 *
27 * The two WP-Stats rows this plugin used to read -- stats_display and
28 * stats_mostlimit -- are deliberately absent. They were shared with six other
29 * plugins rather than owned, so removing WP-EMail must not clear a setting a
30 * sibling is still reading. The migration deletes them once it has folded them
31 * in; uninstall never touches them.
32 *
33 * @return void
34 */
35 function wp_email_delete_options() {
36 $option_names = array(
37 'wp_email_options',
38 'wp_email_version',
39 'widget_email',
40 'widget_email_most_emailed',
41 // Pre-3.0.0 rows.
42 'email_options',
43 'email_db_version',
44 'email_contenttype',
45 'email_snippet',
46 'email_interval',
47 'email_multiple',
48 'email_imageverify',
49 'email_fields',
50 'email_template_title',
51 'email_template_subtitle',
52 'email_template_subject',
53 'email_template_body',
54 'email_template_bodyalt',
55 'email_template_sentsuccess',
56 'email_template_sentfailed',
57 'email_template_error',
58 'email_smtp',
59 'email_mailer',
60 );
61
62 foreach ( $option_names as $option_name ) {
63 delete_option( $option_name );
64 }
65
66 WP_Email_Form::delete_flood_records();
67 }
68
69
70 /**
71 * Take the plugin's capability back off every role that has it.
72 *
73 * @return void
74 */
75 function wp_email_remove_capability() {
76 // One expression, asked and answered: the capability the screens check is
77 // the one granted and the one taken back. Testing the constant while
78 // removing the filtered value would walk straight past a site that filters
79 // wp_email_capability, leaving a capability nothing removes.
80 $capability = WP_Email_Admin::capability();
81
82 foreach ( wp_roles()->role_objects as $role ) {
83 if ( $role->has_cap( $capability ) ) {
84 $role->remove_cap( $capability );
85 }
86 }
87 }
88
89 if ( is_multisite() ) {
90 // 'number' => 0 lifts WP_Site_Query's default cap of 100, which would
91 // otherwise leave the options and the table behind on every site past the
92 // hundredth while still reporting a clean uninstall.
93 $wp_email_site_ids = get_sites(
94 array(
95 'fields' => 'ids',
96 'number' => 0,
97 )
98 );
99
100 foreach ( $wp_email_site_ids as $wp_email_site_id ) {
101 switch_to_blog( (int) $wp_email_site_id );
102
103 wp_email_delete_options();
104 WP_Email_Logs::drop_table();
105 wp_email_remove_capability();
106
107 // Inside the loop: switch_to_blog() pushes onto a stack, so restoring
108 // once after the loop leaves it unwound by exactly one.
109 restore_current_blog();
110 }
111 } else {
112 wp_email_delete_options();
113 WP_Email_Logs::drop_table();
114 wp_email_remove_capability();
115 }
116