| @@ -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,25 +139,25 @@ | ||
| 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 | |
| 159 | + // Delete options from each blog on network. | |
| 139 | 160 | foreach ( wp_stream_get_sites() as $blog ) { |
| 140 | 161 | $this->delete_blog_options( absint( $blog->blog_id ) ); |
| 141 | 162 | } |
| 142 | 163 | } |
| @@ -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,12 +173,12 @@ | ||
| 152 | 173 | } |
| 153 | 174 | |
| 154 | 175 | global $wpdb; |
| 155 | 176 | |
| 156 | - // Wildcard matches | |
| 177 | + // Wildcard matches. | |
| 157 | 178 | $wpdb->query( "DELETE FROM {$wpdb->prefix}options WHERE option_name LIKE '%wp_stream%';" ); |
| 158 | 179 | |
| 159 | - // Specific options | |
| 180 | + // Specific options. | |
| 160 | 181 | foreach ( $this->options as $option ) { |
| 161 | 182 | delete_blog_option( $blog_id, $option ); |
| 162 | 183 | } |
| 163 | 184 | } |
| @@ -167,12 +188,12 @@ | ||
| 167 | 188 | */ |
| 168 | 189 | private function delete_all_user_meta() { |
| 169 | 190 | global $wpdb; |
| 170 | 191 | |
| 171 | - // Wildcard matches | |
| 192 | + // Wildcard matches. | |
| 172 | 193 | $wpdb->query( "DELETE FROM {$wpdb->usermeta} WHERE meta_key LIKE '%wp_stream%';" ); |
| 173 | 194 | |
| 174 | - // Specific user meta | |
| 195 | + // Specific user meta. | |
| 175 | 196 | foreach ( $this->user_meta as $meta_key ) { |
| 176 | 197 | $wpdb->query( |
| 177 | 198 | $wpdb->prepare( "DELETE FROM {$wpdb->usermeta} WHERE meta_key = %s;", $meta_key ) |
| 178 | 199 | ); |
| @@ -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,15 +211,15 @@ | ||
| 190 | 211 | } |
| 191 | 212 | |
| 192 | 213 | global $wpdb; |
| 193 | 214 | |
| 194 | - // Wildcard matches | |
| 215 | + // Wildcard matches. | |
| 195 | 216 | $wpdb->query( "DELETE FROM {$wpdb->usermeta} WHERE meta_key LIKE '{$wpdb->prefix}%wp_stream%';" ); |
| 196 | 217 | |
| 197 | - // Specific user meta | |
| 218 | + // Specific user meta. | |
| 198 | 219 | foreach ( $this->user_meta as $meta_key ) { |
| 199 | 220 | $wpdb->query( |
| 200 | - $wpdb->prepare( "DELETE FROM {$wpdb->usermeta} WHERE meta_key = '{$wpdb->prefix}%s';", $meta_key ) | |
| 221 | + $wpdb->prepare( "DELETE FROM {$wpdb->usermeta} WHERE meta_key = {$wpdb->prefix}%s;", $meta_key ) | |
| 201 | 222 | ); |
| 202 | 223 | } |
| 203 | 224 | } |
| 204 | 225 | |