PluginProbe
WP-Stats / trunk
WP-Stats vtrunk
3.0.1 3.0.0 trunk 1.00 2.00 2.01 2.02 2.03 2.04 2.05 2.06 2.10 2.11 2.20 2.30 2.31 2.40 2.50 2.55 2.56 2.56.1
wp-stats / uninstall.php

uninstall.php in WP-Stats trunk, at uninstall.php

71 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Uninstall WP-Stats.
4 *
5 * Runs with the plugin inactive, so nothing here may depend on the plugin's own
6 * classes or constants being loaded. The row names are therefore spelled out
7 * rather than read from WP_Stats_Options.
8 *
9 * @package WP-Stats
10 */
11
12 defined( 'WP_UNINSTALL_PLUGIN' ) || exit;
13
14 /**
15 * Delete the plugin's rows for the current site.
16 *
17 * The pre-3.0.0 names are still listed: an install deactivated before the
18 * migration fired would otherwise keep them for ever, and tests/test-metadata.php
19 * asserts over wp_options with a LIKE rather than naming rows, so a row added
20 * later and forgotten here fails the suite.
21 *
22 * @return void
23 */
24 function wp_stats_uninstall_site() {
25 $option_names = array(
26 // The settings row and the upgrade markers.
27 'wp_stats_options',
28 'wp_stats_version',
29 // Pre-3.0.0 rows, including the unprefixed name an unreleased 3.0.0
30 // build used before the prefix rule landed.
31 'stats_options',
32 'stats_db_version',
33 'stats_mostlimit',
34 'stats_display',
35 'stats_url',
36 // Widget instances.
37 'widget_stats',
38 );
39
40 foreach ( $option_names as $option_name ) {
41 delete_option( $option_name );
42 }
43 }
44
45 if ( is_multisite() ) {
46 /*
47 * 'number' => 0 lifts WP_Site_Query's default cap of 100, which would
48 * otherwise leave the rows behind on every site past the hundredth while
49 * still reporting a successful uninstall. 'fields' => 'ids' avoids
50 * hydrating WP_Site objects the loop never looks at.
51 */
52 $wp_stats_site_ids = get_sites(
53 array(
54 'fields' => 'ids',
55 'number' => 0,
56 )
57 );
58
59 foreach ( $wp_stats_site_ids as $wp_stats_site_id ) {
60 // Inside the loop: switch_to_blog() pushes onto a stack, so restoring once
61 // after the loop unwinds it by exactly one.
62 switch_to_blog( (int) $wp_stats_site_id );
63
64 wp_stats_uninstall_site();
65
66 restore_current_blog();
67 }
68 } else {
69 wp_stats_uninstall_site();
70 }
71