display-conditions
3 years ago
front
10 months ago
helpers
10 months ago
metas
3 years ago
multisite
3 years ago
palettes
3 years ago
provider
3 years ago
providers
10 months ago
templates
3 years ago
update
3 years ago
class-hustle-admin-page-abstract.php
10 months ago
class-hustle-black-friday-campaign.php
7 months ago
class-hustle-condition-factory.php
6 years ago
class-hustle-cross-sell.php
10 months ago
class-hustle-dashboard-admin.php
3 years ago
class-hustle-data.php
3 years ago
class-hustle-db.php
2 years ago
class-hustle-installer.php
4 years ago
class-hustle-meta.php
3 years ago
class-hustle-module-admin.php
10 months ago
class-hustle-module-collection.php
3 years ago
class-hustle-module-page-abstract.php
2 years ago
class-hustle-notifications.php
3 years ago
class-hustle-settings-admin.php
3 years ago
class-hustle-tutorials-page.php
4 years ago
class-hustle-wp-dashboard-page.php
3 years ago
hustle-deletion.php
3 years ago
hustle-embedded-admin.php
3 years ago
hustle-entries-admin.php
3 years ago
hustle-entry-model.php
3 years ago
hustle-general-data-protection.php
3 years ago
hustle-init.php
7 months ago
hustle-mail.php
3 years ago
hustle-migration.php
3 years ago
hustle-model.php
3 years ago
hustle-module-model.php
10 months ago
hustle-module-widget-legacy.php
3 years ago
hustle-module-widget.php
3 years ago
hustle-modules-common-admin-ajax.php
10 months ago
hustle-popup-admin.php
3 years ago
hustle-providers-admin.php
3 years ago
hustle-providers.php
3 years ago
hustle-settings-admin-ajax.php
3 years ago
hustle-settings-page.php
3 years ago
hustle-slidein-admin.php
3 years ago
hustle-sshare-admin.php
3 years ago
hustle-sshare-model.php
3 years ago
hustle-tracking-model.php
3 years ago
opt-in-geo.php
10 months ago
opt-in-utils.php
3 years ago
opt-in-wpmudev-api.php
3 years ago
hustle-deletion.php
247 lines
| 1 | <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName |
| 2 | /** |
| 3 | * Hustle_Deletion |
| 4 | * |
| 5 | * @package Hustle |
| 6 | */ |
| 7 | |
| 8 | /** |
| 9 | * Methods for the plugin's data deletion. |
| 10 | * |
| 11 | * @since 4.0.3 |
| 12 | */ |
| 13 | class Hustle_Deletion { |
| 14 | |
| 15 | /** |
| 16 | * Reset onboarding notification |
| 17 | * |
| 18 | * @since 4.0.3 |
| 19 | */ |
| 20 | public static function hustle_reset_notifications() { |
| 21 | $meta_key = 'hustle_dismissed_notifications'; |
| 22 | delete_metadata( 'user', '', $meta_key, '', true ); |
| 23 | } |
| 24 | |
| 25 | /** |
| 26 | * Delete custom options |
| 27 | * |
| 28 | * @since 4.0.3 |
| 29 | */ |
| 30 | public static function hustle_delete_custom_options() { |
| 31 | delete_option( 'hustle_version' ); |
| 32 | delete_site_option( 'hustle_version' ); |
| 33 | delete_option( 'hustle_color_index' ); |
| 34 | delete_option( 'hustle_database_version' ); |
| 35 | delete_option( 'hustle_unsubscribe_nonces' ); |
| 36 | delete_option( 'hustle_migrations' ); |
| 37 | delete_option( 'hustle_previous_version' ); |
| 38 | delete_option( 'hustle_30_migration_data' ); |
| 39 | delete_option( 'hustle_settings' ); |
| 40 | delete_option( 'hustle_ss_refresh_counters' ); |
| 41 | delete_option( 'wpoi-county-id-map' ); |
| 42 | delete_option( 'hustle_custom_nonce' ); |
| 43 | delete_option( 'hustle_activated_flag' ); |
| 44 | delete_option( 'hustle_new_welcome_notice_dismissed' ); |
| 45 | delete_option( 'hustle_popup_migrated' ); |
| 46 | delete_option( 'hustle_global_unsubscription_settings' ); |
| 47 | delete_option( 'hustle_global_email_settings' ); |
| 48 | delete_option( 'hustle_database_version' ); |
| 49 | delete_option( 'widget_hustle_module_widget' ); |
| 50 | delete_option( 'opt_in_database_version' ); |
| 51 | delete_option( 'hustle_custom_palettes' ); |
| 52 | delete_option( 'hustle_notice_stop_support_m2' ); |
| 53 | delete_option( 'hustle-hide_tutorials' ); |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Delete options created by Packaged Hustle Addons. |
| 58 | * |
| 59 | * @since 4.0.3 |
| 60 | * @param array $addons Existing addons as $slug => Hustle_Provider_Abstract instance. |
| 61 | */ |
| 62 | public static function hustle_delete_addon_options( $addons = array() ) { |
| 63 | delete_option( 'hustle_activated_providers' ); |
| 64 | if ( empty( $addons ) ) { |
| 65 | $addons = array_keys( Hustle_Provider_Utils::get_registered_providers_list() ); |
| 66 | } |
| 67 | |
| 68 | foreach ( $addons as $slug ) { |
| 69 | delete_option( "hustle_provider_{$slug}_version" ); |
| 70 | delete_option( "hustle_provider_{$slug}_settings" ); |
| 71 | |
| 72 | if ( 'constantcontact' === $slug || 'hubspot' === $slug ) { |
| 73 | delete_option( 'hustle_opt-in-constant_contact-token' ); |
| 74 | delete_option( "hustle_opt-in-{$slug}-token" ); |
| 75 | delete_option( "hustle_{$slug}_referer" ); |
| 76 | delete_option( "hustle_{$slug}_current_page" ); |
| 77 | |
| 78 | } elseif ( 'aweber' === $slug ) { |
| 79 | // Old options. |
| 80 | delete_option( "{$slug}_access_token" ); |
| 81 | delete_option( "{$slug}_access_secret" ); |
| 82 | delete_option( "{$slug}_aut_code" ); |
| 83 | delete_option( "{$slug}_consumer_secret" ); |
| 84 | delete_option( "{$slug}_consumer_key" ); |
| 85 | |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Clear modules. |
| 93 | * |
| 94 | * @since 4.0.3 |
| 95 | */ |
| 96 | public static function hustle_clear_modules() { |
| 97 | global $wpdb; |
| 98 | |
| 99 | // Get max module id. |
| 100 | $max_module_id_query = "SELECT MAX(`module_id`) FROM {$wpdb->prefix}hustle_modules"; |
| 101 | $max_module_id = (int) $wpdb->get_var( $max_module_id_query ); // phpcs:ignore |
| 102 | |
| 103 | // Get max module meta id. |
| 104 | $max_module_meta_id_query = "SELECT MAX(`meta_id`) FROM {$wpdb->prefix}hustle_modules_meta"; |
| 105 | $max_module_meta_id = (int) $wpdb->get_var( $max_module_meta_id_query ); // phpcs:ignore |
| 106 | |
| 107 | // Delete module cache. |
| 108 | if ( $max_module_id && is_numeric( $max_module_id ) && $max_module_id > 0 ) { |
| 109 | for ( $i = 1; $i <= $max_module_id; $i ++ ) { |
| 110 | wp_cache_delete( $i, 'hustle_model_data' ); |
| 111 | wp_cache_delete( $i, 'hustle_module_meta' ); |
| 112 | wp_cache_delete( $i, 'hustle_subscribed_emails' ); |
| 113 | wp_cache_delete( $i, 'hustle_module_type' ); |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | /** |
| 118 | * Hook to reset auto increment on entries reset. |
| 119 | * This is discouraged becuase users might run into |
| 120 | * cookie conflict. |
| 121 | * |
| 122 | * @since 4.0.3 |
| 123 | * |
| 124 | * @param boolen |
| 125 | */ |
| 126 | $maintain_auto_increment = apply_filters( 'maintain_modules_auto_increment', true ); |
| 127 | |
| 128 | if ( $maintain_auto_increment ) { |
| 129 | |
| 130 | // Alter auto increment for cookie compatibility. |
| 131 | $alter_modules = $wpdb->prepare( |
| 132 | "ALTER TABLE {$wpdb->prefix}hustle_modules |
| 133 | AUTO_INCREMENT = %d", |
| 134 | ++$max_module_id |
| 135 | ); |
| 136 | $alter_meta = $wpdb->prepare( |
| 137 | "ALTER TABLE {$wpdb->prefix}hustle_modules_meta |
| 138 | AUTO_INCREMENT = %d", |
| 139 | ++$max_module_meta_id |
| 140 | ); |
| 141 | |
| 142 | $wpdb->query( "TRUNCATE {$wpdb->prefix}hustle_modules" );// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery |
| 143 | $wpdb->query( $alter_modules );// phpcs:ignore |
| 144 | |
| 145 | $wpdb->query( "TRUNCATE {$wpdb->prefix}hustle_modules_meta" );// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery |
| 146 | $wpdb->query( $alter_meta );// phpcs:ignore |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | /** |
| 151 | * Clear submissions. |
| 152 | * |
| 153 | * @since 4.0.3 |
| 154 | */ |
| 155 | public static function hustle_clear_module_submissions() { |
| 156 | global $wpdb; |
| 157 | |
| 158 | // Delete entry cache. |
| 159 | $max_entry_id_query = "SELECT MAX(`entry_id`) FROM {$wpdb->prefix}hustle_entries"; |
| 160 | $max_entry_id = $wpdb->get_var( $max_entry_id_query ); // phpcs:ignore |
| 161 | |
| 162 | // Get entry meta id. |
| 163 | $max_entry_meta_id_query = "SELECT MAX(`meta_id`) FROM {$wpdb->prefix}hustle_entries_meta"; |
| 164 | $max_entry_meta_id = $wpdb->get_var( $max_entry_meta_id_query ); // phpcs:ignore |
| 165 | |
| 166 | if ( $max_entry_id && is_numeric( $max_entry_id ) && $max_entry_id > 0 ) { |
| 167 | for ( $i = 1; $i <= $max_entry_id; $i ++ ) { |
| 168 | wp_cache_delete( $i, 'Hustle_Entry_Model' ); |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | $wpdb->query( "TRUNCATE {$wpdb->prefix}hustle_entries" );// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery |
| 173 | |
| 174 | $wpdb->query( "TRUNCATE {$wpdb->prefix}hustle_entries_meta" );// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery |
| 175 | |
| 176 | /** |
| 177 | * Hook to reset auto increment on entries reset. |
| 178 | * |
| 179 | * This is discouraged becuase users might run into |
| 180 | * cookie conflict. |
| 181 | * |
| 182 | * @since 4.0.2 |
| 183 | * |
| 184 | * @param boolen |
| 185 | */ |
| 186 | $maintain_auto_increment = apply_filters( 'maintain_entries_auto_increment', true ); |
| 187 | |
| 188 | if ( $maintain_auto_increment ) { |
| 189 | |
| 190 | // Alter auto increment for cookie compatibility. |
| 191 | $alter_entries = $wpdb->prepare( |
| 192 | "ALTER TABLE {$wpdb->prefix}hustle_entries |
| 193 | AUTO_INCREMENT = %d", |
| 194 | ++$max_entry_id |
| 195 | ); |
| 196 | |
| 197 | $alter_meta = $wpdb->prepare( |
| 198 | "ALTER TABLE {$wpdb->prefix}hustle_entries_meta |
| 199 | AUTO_INCREMENT = %d", |
| 200 | ++$max_entry_meta_id |
| 201 | ); |
| 202 | $wpdb->query( $alter_entries );// phpcs:ignore |
| 203 | $wpdb->query( $alter_meta );// phpcs:ignore |
| 204 | } |
| 205 | wp_cache_delete( 'all_module_types', 'hustle_total_entries' ); |
| 206 | wp_cache_delete( 'global_count', 'hustle_total_entries' ); |
| 207 | wp_cache_delete( 'hustle_icontact_account_id', 'HUSTLE_ICONTACT_API_CACHE' ); |
| 208 | wp_cache_delete( 'hustle_icontact_client_folder_id', 'HUSTLE_ICONTACT_API_CACHE' ); |
| 209 | } |
| 210 | |
| 211 | /** |
| 212 | * Clear views. |
| 213 | * |
| 214 | * @since 4.0.3 |
| 215 | */ |
| 216 | public static function hustle_clear_module_views() { |
| 217 | global $wpdb; |
| 218 | $wpdb->query( "TRUNCATE {$wpdb->prefix}hustle_tracking" );// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching |
| 219 | } |
| 220 | |
| 221 | /** |
| 222 | * Drop custom tables. |
| 223 | * |
| 224 | * @since 4.0.3 |
| 225 | */ |
| 226 | public static function hustle_drop_custom_tables() { |
| 227 | global $wpdb; |
| 228 | $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}hustle_entries" );// phpcs:ignore |
| 229 | $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}hustle_entries_meta" );// phpcs:ignore |
| 230 | $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}hustle_modules" );// phpcs:ignore |
| 231 | $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}hustle_modules_meta" );// phpcs:ignore |
| 232 | $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}hustle_tracking" );// phpcs:ignore |
| 233 | $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}optin_meta" );// phpcs:ignore |
| 234 | $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}optins" );// phpcs:ignore |
| 235 | } |
| 236 | |
| 237 | /** |
| 238 | * Removes cronjobs. |
| 239 | * |
| 240 | * @since 4.3.3 |
| 241 | */ |
| 242 | public static function clear_cronjobs() { |
| 243 | // Remove the cron for refreshing Aweber's token. |
| 244 | wp_clear_scheduled_hook( 'hustle_aweber_token_refresh' ); |
| 245 | } |
| 246 | } |
| 247 |