PluginProbe
Stream – Activity Log & Audit Trail / 3.8.2
Stream – Activity Log & Audit Trail v3.8.2
4.4.0 4.3.0 4.2.2 4.2.1 trunk 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.1 3.1.1 3.10.0 3.2.0 3.2.1 3.2.2 3.2.3 All 50 releases
← All changes | classes/class-uninstall.php +59 -38 3.0.13.8.2 View file →
@@ -1,10 +1,20 @@
1 1 <?php
2 +/**
3 + * Manages the uninstallation of the plugin.
4 + *
5 + * @package WP_Stream
6 + */
7 +
2 8 namespace WP_Stream;
3 9
10 +/**
11 + * Class - Uninstall
12 + */
4 13 class Uninstall {
5 14 /**
6 - * Hold Plugin class
15 + * Holds Instance of plugin object
16 + *
7 17 * @var Plugin
8 18 */
9 19 public $plugin;
10 20
@@ -21,16 +31,21 @@
21 31 * @var array
22 32 */
23 33 public $user_meta;
24 34
25 - function __construct( $plugin ) {
35 + /**
36 + * Class constructor
37 + *
38 + * @param Plugin $plugin Instance of plugin object.
39 + */
40 + public function __construct( $plugin ) {
26 41 $this->plugin = $plugin;
27 42
28 43 $this->user_meta = array(
29 44 'edit_stream_per_page',
30 - 'stream_last_read', // Deprecated
31 - 'stream_unread_count', // Deprecated
32 - 'stream_user_feed_key', // Deprecated
45 + 'stream_last_read', // Deprecated.
46 + 'stream_unread_count', // Deprecated.
47 + 'stream_user_feed_key', // Deprecated.
33 48 );
34 49 }
35 50
36 51 /**
@@ -36,10 +51,8 @@
36 51 /**
37 52 * Uninstall Stream by deleting its data
38 53 */
39 54 public function uninstall() {
40 - //check_ajax_referer( 'stream_nonce', 'wp_stream_nonce' );
41 -
42 55 $this->options = array(
43 56 $this->plugin->install->option_key,
44 57 $this->plugin->settings->option_key,
45 58 $this->plugin->settings->network_options_key,
@@ -44,9 +57,9 @@
44 57 $this->plugin->settings->option_key,
45 58 $this->plugin->settings->network_options_key,
46 59 );
47 60
48 - // Verify current user's permissions before proceeding
61 + // Verify current user's permissions before proceeding.
49 62 if ( ! current_user_can( $this->plugin->admin->settings_cap ) ) {
50 63 wp_die(
51 64 esc_html__( "You don't have sufficient privileges to do this action.", 'stream' )
52 65 );
@@ -51,19 +64,27 @@
51 64 esc_html__( "You don't have sufficient privileges to do this action.", 'stream' )
52 65 );
53 66 }
54 67
55 - // Prevent this action from firing
68 + if ( defined( 'DISALLOW_FILE_MODS' ) && true === DISALLOW_FILE_MODS ) {
69 + wp_die(
70 + esc_html__( "You don't have sufficient file permissions to do this action.", 'stream' )
71 + );
72 + }
73 +
74 + // Prevent this action from firing.
56 75 remove_action( 'deactivate_plugin', array( 'Connector_Installer', 'callback' ), null );
57 76
58 - // Just in case
77 + // Just in case.
59 78 if ( ! function_exists( 'is_plugin_active_for_network' ) ) {
60 79 require_once ABSPATH . '/wp-admin/includes/plugin.php';
61 80 }
62 81
63 - // Drop everything on single site installs or when network activated
64 - // Otherwise only delete data relative to the current blog
65 - if ( ! is_multisite() || is_plugin_active_for_network( $this->plugin->locations['plugin'] ) ) {
82 + /**
83 + * Drop everything on single site installs or when network activated
84 + * Otherwise only delete data relative to the current blog.
85 + */
86 + if ( ! is_multisite() || $this->plugin->is_network_activated() ) {
66 87 $this->delete_all_records();
67 88 $this->delete_all_options();
68 89 $this->delete_all_user_meta();
69 90 } else {
@@ -91,9 +112,9 @@
91 112
92 113 /**
93 114 * Delete records and record meta from a specific blog
94 115 *
95 - * @param int $blog_id (optional)
116 + * @param int $blog_id Blog ID (optional).
96 117 */
97 118 private function delete_blog_records( $blog_id = 1 ) {
98 119 if ( empty( $blog_id ) || ! is_int( $blog_id ) ) {
99 120 return;
@@ -118,27 +139,27 @@
118 139 */
119 140 private function delete_all_options() {
120 141 global $wpdb;
121 142
122 - // Wildcard matches
143 + // Wildcard matches.
123 144 $wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE '%wp_stream%';" );
124 145
125 - // Specific options
146 + // Specific options.
126 147 foreach ( $this->options as $option ) {
127 - delete_site_option( $option ); // Supports both multisite and single site installs
148 + delete_site_option( $option ); // Supports both multisite and single site installs.
128 149 }
129 150
130 - // Single site installs can stop here
151 + // Single site installs can stop here.
131 152 if ( ! is_multisite() ) {
132 153 return;
133 154 }
134 155
135 - // Wildcard matches on network options
156 + // Wildcard matches on network options.
136 157 $wpdb->query( "DELETE FROM {$wpdb->sitemeta} WHERE meta_key LIKE '%wp_stream%';" );
137 158
138 - // Delete options from each blog on network
139 - foreach ( wp_get_sites() as $blog ) {
140 - $this->delete_blog_options( absint( $blog['blog_id'] ) );
159 + // Delete options from each blog on network.
160 + foreach ( wp_stream_get_sites() as $blog ) {
161 + $this->delete_blog_options( absint( $blog->blog_id ) );
141 162 }
142 163 }
143 164
144 165 /**
@@ -143,9 +164,9 @@
143 164
144 165 /**
145 166 * Delete options from a specific blog
146 167 *
147 - * @param int $blog_id (optional)
168 + * @param int $blog_id Blog ID (optional).
148 169 */
149 170 private function delete_blog_options( $blog_id = 1 ) {
150 171 if ( empty( $blog_id ) || ! is_int( $blog_id ) ) {
151 172 return;
@@ -152,14 +173,12 @@
152 173 }
153 174
154 175 global $wpdb;
155 176
156 - $blog_prefix = $wpdb->get_blog_prefix( $blog_id );
177 + // Wildcard matches.
178 + $wpdb->query( "DELETE FROM {$wpdb->prefix}options WHERE option_name LIKE '%wp_stream%';" );
157 179
158 - // Wildcard matches
159 - $wpdb->query( "DELETE FROM {$blog_prefix}options WHERE option_name LIKE '%wp_stream%';" );
160 -
161 - // Specific options
180 + // Specific options.
162 181 foreach ( $this->options as $option ) {
163 182 delete_blog_option( $blog_id, $option );
164 183 }
165 184 }
@@ -169,14 +188,16 @@
169 188 */
170 189 private function delete_all_user_meta() {
171 190 global $wpdb;
172 191
173 - // Wildcard matches
192 + // Wildcard matches.
174 193 $wpdb->query( "DELETE FROM {$wpdb->usermeta} WHERE meta_key LIKE '%wp_stream%';" );
175 194
176 - // Specific user meta
195 + // Specific user meta.
177 196 foreach ( $this->user_meta as $meta_key ) {
178 - $wpdb->query( "DELETE FROM {$wpdb->usermeta} WHERE meta_key = '{$meta_key}';" );
197 + $wpdb->query(
198 + $wpdb->prepare( "DELETE FROM {$wpdb->usermeta} WHERE meta_key = %s;", $meta_key )
199 + );
179 200 }
180 201 }
181 202
182 203 /**
@@ -181,9 +202,9 @@
181 202
182 203 /**
183 204 * Delete user meta from a specific blog
184 205 *
185 - * @param int $blog_id (optional)
206 + * @param int $blog_id Blog ID (optional).
186 207 */
187 208 private function delete_blog_user_meta( $blog_id = 1 ) {
188 209 if ( empty( $blog_id ) || ! is_int( $blog_id ) ) {
189 210 return;
@@ -190,16 +211,16 @@
190 211 }
191 212
192 213 global $wpdb;
193 214
194 - $blog_prefix = $wpdb->get_blog_prefix( $blog_id );
215 + // Wildcard matches.
216 + $wpdb->query( "DELETE FROM {$wpdb->usermeta} WHERE meta_key LIKE '{$wpdb->prefix}%wp_stream%';" );
195 217
196 - // Wildcard matches
197 - $wpdb->query( "DELETE FROM {$wpdb->usermeta} WHERE meta_key LIKE '{$blog_prefix}%wp_stream%';" );
198 -
199 - // Specific user meta
218 + // Specific user meta.
200 219 foreach ( $this->user_meta as $meta_key ) {
201 - $wpdb->query( "DELETE FROM {$wpdb->usermeta} WHERE meta_key = '{$blog_prefix}{$meta_key}';" );
220 + $wpdb->query(
221 + $wpdb->prepare( "DELETE FROM {$wpdb->usermeta} WHERE meta_key = {$wpdb->prefix}%s;", $meta_key )
222 + );
202 223 }
203 224 }
204 225
205 226 /**