| 1 |
<?php |
| 2 |
/** |
| 3 |
* Uninstall WP-ShowHide. |
| 4 |
* |
| 5 |
* Runs with the plugin inactive, so nothing here may depend on the plugin's |
| 6 |
* own classes or constants being loaded. The row name is therefore spelled out |
| 7 |
* rather than read from WP_ShowHide_Options. |
| 8 |
* |
| 9 |
* @package WP-ShowHide |
| 10 |
*/ |
| 11 |
|
| 12 |
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { |
| 13 |
exit(); |
| 14 |
} |
| 15 |
|
| 16 |
/** |
| 17 |
* Delete the plugin's options for the current site. |
| 18 |
* |
| 19 |
* One row only: WP-ShowHide has nothing a site owner can configure and so |
| 20 |
* stores no settings row at all (STANDARDS.md 2.1). If it ever grows one, it |
| 21 |
* gets deleted here too -- tests/test-metadata.php asserts over wp_options with |
| 22 |
* a LIKE rather than naming rows, so a forgotten row fails the suite. |
| 23 |
* |
| 24 |
* @return void |
| 25 |
*/ |
| 26 |
function wp_showhide_uninstall_site() { |
| 27 |
delete_option( 'wp_showhide_version' ); |
| 28 |
} |
| 29 |
|
| 30 |
if ( is_multisite() ) { |
| 31 |
/* |
| 32 |
* 'number' => 0 lifts WP_Site_Query's default cap of 100, which would |
| 33 |
* otherwise leave the rows behind on every site past the hundredth while |
| 34 |
* still reporting a successful uninstall. 'fields' => 'ids' avoids |
| 35 |
* hydrating WP_Site objects the loop never looks at. |
| 36 |
*/ |
| 37 |
$wp_showhide_site_ids = get_sites( |
| 38 |
array( |
| 39 |
'fields' => 'ids', |
| 40 |
'number' => 0, |
| 41 |
) |
| 42 |
); |
| 43 |
|
| 44 |
foreach ( $wp_showhide_site_ids as $wp_showhide_site_id ) { |
| 45 |
// switch_to_blog() pushes onto a stack, so the restore belongs inside |
| 46 |
// the loop -- restoring once at the end leaves it unwound by one. |
| 47 |
switch_to_blog( (int) $wp_showhide_site_id ); |
| 48 |
|
| 49 |
wp_showhide_uninstall_site(); |
| 50 |
|
| 51 |
restore_current_blog(); |
| 52 |
} |
| 53 |
} else { |
| 54 |
wp_showhide_uninstall_site(); |
| 55 |
} |
| 56 |
|