| 1 |
<?php |
| 2 |
/** |
| 3 |
* Runs when the administrator deletes Contact Forms from the Plugins screen. |
| 4 |
* |
| 5 |
* It removes the plugin's data ONLY if the administrator asked for it in |
| 6 |
* Settings → Danger Zone. The default is to keep everything: deleting a plugin |
| 7 |
* is often a step in reinstalling or troubleshooting it, and years of |
| 8 |
* submissions must not disappear because of it. Without the opt-in this file |
| 9 |
* does nothing at all. |
| 10 |
* |
| 11 |
* WordPress includes this file with the plugin NOT loaded - no constants, no |
| 12 |
* classes, none of its functions exist - so everything needed is required here |
| 13 |
* explicitly. includes/data-deletion.php is written for exactly that: it |
| 14 |
* defines functions and registers no hooks. |
| 15 |
* |
| 16 |
* @since 2.3.0 |
| 17 |
* @package Contact Forms by Cimatti |
| 18 |
*/ |
| 19 |
|
| 20 |
// Refuse to run outside the uninstall routine WordPress calls this file from. |
| 21 |
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { |
| 22 |
exit; |
| 23 |
} |
| 24 |
|
| 25 |
require_once __DIR__ . '/includes/data-deletion.php'; |
| 26 |
|
| 27 |
/** |
| 28 |
* Delete the data of the current site, if that site opted in. |
| 29 |
* |
| 30 |
* The preference, the options and the submission tables are all per-site, so on |
| 31 |
* a network each site answers for itself: one blog opting in never empties |
| 32 |
* another. |
| 33 |
* |
| 34 |
* @since 2.3.0 |
| 35 |
*/ |
| 36 |
function accua_forms_uninstall_current_site() { |
| 37 |
if ( ! accua_forms_delete_data_on_uninstall() ) { |
| 38 |
return; |
| 39 |
} |
| 40 |
|
| 41 |
_accua_forms_delete_all_plugin_data(); |
| 42 |
|
| 43 |
// That routine ends by setting a short-lived flag which stops the schema |
| 44 |
// being recreated during the deactivation redirect. There is no next request |
| 45 |
// for this plugin here, so the flag would just be the one row left behind. |
| 46 |
delete_transient( '_accua_forms_data_deleted' ); |
| 47 |
} |
| 48 |
|
| 49 |
if ( ! is_multisite() ) { |
| 50 |
accua_forms_uninstall_current_site(); |
| 51 |
return; |
| 52 |
} |
| 53 |
|
| 54 |
// On a network, walk every site in batches rather than loading the whole list: |
| 55 |
// get_sites() with no limit would hold every site of a large network in memory |
| 56 |
// at once, and this runs during a single admin request. |
| 57 |
$accua_forms_offset = 0; |
| 58 |
$accua_forms_batch = 100; |
| 59 |
|
| 60 |
do { |
| 61 |
$accua_forms_site_ids = get_sites( array( |
| 62 |
'fields' => 'ids', |
| 63 |
'number' => $accua_forms_batch, |
| 64 |
'offset' => $accua_forms_offset, |
| 65 |
'orderby' => 'id', |
| 66 |
'network_id' => 0, |
| 67 |
) ); |
| 68 |
|
| 69 |
foreach ( $accua_forms_site_ids as $accua_forms_site_id ) { |
| 70 |
switch_to_blog( $accua_forms_site_id ); |
| 71 |
accua_forms_uninstall_current_site(); |
| 72 |
restore_current_blog(); |
| 73 |
} |
| 74 |
|
| 75 |
$accua_forms_offset += $accua_forms_batch; |
| 76 |
} while ( count( $accua_forms_site_ids ) === $accua_forms_batch ); |
| 77 |
|