atarim-visual-collaboration
Last commit date
admin
2 weeks ago
assets
2 weeks ago
doit
2 weeks ago
images
2 weeks ago
includes
2 weeks ago
third-party
2 weeks ago
vendor
2 weeks ago
atarim-visual-collaboration.php
2 weeks ago
composer.json
2 weeks ago
composer.lock
2 weeks ago
readme.txt
2 weeks ago
uninstall.php
2 weeks ago
uninstall.php
105 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Atarim uninstall routine. |
| 4 | * |
| 5 | * Runs only when the plugin is deleted from WordPress. It removes all plugin |
| 6 | * data ONLY if the user explicitly chose "Delete all data" in the delete modal |
| 7 | * (stored in the avc_remove_data_on_uninstall option). If that option is not |
| 8 | * '1' (the default, including bulk/WP-CLI deletes), nothing is touched. |
| 9 | */ |
| 10 | |
| 11 | if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { |
| 12 | exit; |
| 13 | } |
| 14 | |
| 15 | if ( ! defined( 'AVCF_UNINSTALL_PREF_OPTION' ) ) { |
| 16 | define( 'AVCF_UNINSTALL_PREF_OPTION', 'avc_remove_data_on_uninstall' ); |
| 17 | } |
| 18 | |
| 19 | /** |
| 20 | * Wipe every option, user meta key and transient the plugin owns for the |
| 21 | * current site context. |
| 22 | */ |
| 23 | function avcf_uninstall_cleanup_site() { |
| 24 | global $wpdb; |
| 25 | |
| 26 | $options = array( |
| 27 | // Current (avc_*) plugin options. |
| 28 | 'avc_license', |
| 29 | 'avc_site_id', |
| 30 | 'avc_atarim_secret_token', |
| 31 | 'avc_initial_setup_complete', |
| 32 | 'avc_collab_active', |
| 33 | 'avc_website_developer', |
| 34 | 'avc_selected_role', |
| 35 | 'avc_enable_doit', |
| 36 | 'avc_collab_logo', |
| 37 | 'avc_collab_favicon', |
| 38 | 'avc_collab_color', |
| 39 | 'avc_plugin_activation_redirect', |
| 40 | // Legacy (wpf_*) options from earlier plugin versions. |
| 41 | 'wpf_initial_setup_complete', |
| 42 | 'wpf_site_id', |
| 43 | 'wpf_selcted_role', |
| 44 | 'wpf_token', |
| 45 | 'wpf_login', |
| 46 | 'wpf_username', |
| 47 | ); |
| 48 | |
| 49 | foreach ( $options as $option ) { |
| 50 | delete_option( $option ); |
| 51 | } |
| 52 | |
| 53 | // User meta written across all users. |
| 54 | $user_meta_keys = array( |
| 55 | 'avc_user_type', |
| 56 | 'avc_consent_status', |
| 57 | ); |
| 58 | |
| 59 | foreach ( $user_meta_keys as $meta_key ) { |
| 60 | delete_metadata( 'user', 0, $meta_key, '', true ); |
| 61 | } |
| 62 | |
| 63 | // Site-visibility transients use a dynamic suffix (md5 of the site id), |
| 64 | // so clear them by prefix directly from the options table. |
| 65 | $like = $wpdb->esc_like( '_transient_avc_site_visibility_' ) . '%'; |
| 66 | $like_timeout = $wpdb->esc_like( '_transient_timeout_avc_site_visibility_' ) . '%'; |
| 67 | |
| 68 | // phpcs:disable WordPress.DB.DirectDatabaseQuery |
| 69 | $wpdb->query( |
| 70 | $wpdb->prepare( |
| 71 | "DELETE FROM {$wpdb->options} WHERE option_name LIKE %s OR option_name LIKE %s", |
| 72 | $like, |
| 73 | $like_timeout |
| 74 | ) |
| 75 | ); |
| 76 | // phpcs:enable WordPress.DB.DirectDatabaseQuery |
| 77 | |
| 78 | // Finally remove the preference flag itself. |
| 79 | delete_option( AVCF_UNINSTALL_PREF_OPTION ); |
| 80 | } |
| 81 | |
| 82 | $avcf_should_remove = get_option( AVCF_UNINSTALL_PREF_OPTION ); |
| 83 | |
| 84 | if ( '1' !== $avcf_should_remove ) { |
| 85 | // User chose to keep data (or deleted without choosing). Leave everything. |
| 86 | return; |
| 87 | } |
| 88 | |
| 89 | if ( is_multisite() ) { |
| 90 | $site_ids = get_sites( |
| 91 | array( |
| 92 | 'fields' => 'ids', |
| 93 | 'number' => 0, |
| 94 | ) |
| 95 | ); |
| 96 | |
| 97 | foreach ( $site_ids as $blog_id ) { |
| 98 | switch_to_blog( $blog_id ); |
| 99 | avcf_uninstall_cleanup_site(); |
| 100 | restore_current_blog(); |
| 101 | } |
| 102 | } else { |
| 103 | avcf_uninstall_cleanup_site(); |
| 104 | } |
| 105 |