| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Uninstall Ultimate Cursor |
| 5 |
* |
| 6 |
* This file runs when the plugin is deleted (uninstalled) from WordPress. |
| 7 |
* It cleans up all plugin data from the database. |
| 8 |
* |
| 9 |
* @package ultimate-cursor |
| 10 |
*/ |
| 11 |
|
| 12 |
// If uninstall not called from WordPress, exit |
| 13 |
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { |
| 14 |
exit; |
| 15 |
} |
| 16 |
|
| 17 |
/** |
| 18 |
* Fire the Freemius uninstall event so the dashboard sees this uninstall. |
| 19 |
* |
| 20 |
* WordPress core's uninstall_plugin() includes this file INSTEAD OF firing the |
| 21 |
* 'uninstall_{plugin}' action (see wp-admin/includes/plugin.php) whenever a custom |
| 22 |
* uninstall.php exists — so the uninstall hook the Freemius SDK registers via |
| 23 |
* register_uninstall_hook() on deactivation never runs, and _uninstall_plugin_event() |
| 24 |
* is never called. Re-initializing the SDK here and calling it directly is the |
| 25 |
* documented Freemius workaround for plugins with their own uninstall.php. |
| 26 |
*/ |
| 27 |
function ultimate_cursor_fire_freemius_uninstall_event() { |
| 28 |
if ( ! file_exists( __DIR__ . '/vendor/freemius/wordpress-sdk/start.php' ) ) { |
| 29 |
return; |
| 30 |
} |
| 31 |
|
| 32 |
require_once __DIR__ . '/vendor/freemius/wordpress-sdk/start.php'; |
| 33 |
|
| 34 |
if ( ! function_exists( 'fs_dynamic_init' ) ) { |
| 35 |
return; |
| 36 |
} |
| 37 |
|
| 38 |
$fs = fs_dynamic_init( |
| 39 |
array( |
| 40 |
'id' => '19720', |
| 41 |
'slug' => 'ultimate-cursor', |
| 42 |
'premium_slug' => 'ultimate-cursor-pro', |
| 43 |
'type' => 'plugin', |
| 44 |
'public_key' => 'pk_fb94765a4f619e83979c2825626c2', |
| 45 |
'is_premium' => false, |
| 46 |
'is_premium_only' => false, |
| 47 |
'has_paid_plans' => true, |
| 48 |
'is_live' => true, |
| 49 |
'is_org_compliant' => true, |
| 50 |
) |
| 51 |
); |
| 52 |
|
| 53 |
if ( ! is_object( $fs ) ) { |
| 54 |
return; |
| 55 |
} |
| 56 |
|
| 57 |
// Don't fire when the sibling version (premium) is still active — this delete |
| 58 |
// is a version swap, not a real uninstall. Mirrors Freemius::_uninstall_plugin_hook(). |
| 59 |
if ( |
| 60 |
is_plugin_active( $fs->get_plugin_basename() ) || |
| 61 |
is_plugin_active( $fs->premium_plugin_basename() ) |
| 62 |
) { |
| 63 |
return; |
| 64 |
} |
| 65 |
|
| 66 |
$fs->_uninstall_plugin_event(); |
| 67 |
} |
| 68 |
ultimate_cursor_fire_freemius_uninstall_event(); |
| 69 |
|
| 70 |
/** |
| 71 |
* Delete all plugin data for a single site. |
| 72 |
*/ |
| 73 |
function ultimate_cursor_delete_site_data() { |
| 74 |
delete_option( 'ultimate_cursor_settings' ); |
| 75 |
delete_option( 'ultimate_cursor_background_settings' ); |
| 76 |
delete_transient( '_ultimate_cursor_welcome_screen_activation_redirect' ); |
| 77 |
|
| 78 |
// Remove per-user promo-dismissal meta (keys: uc_dismissed_promo_*). |
| 79 |
delete_metadata( 'user', 0, 'uc_dismissed_promo_widget', '', true ); |
| 80 |
delete_metadata( 'user', 0, 'uc_dismissed_promo_notice', '', true ); |
| 81 |
} |
| 82 |
|
| 83 |
// Delete plugin data for the current site. |
| 84 |
ultimate_cursor_delete_site_data(); |
| 85 |
|
| 86 |
// For multisite installations, delete options from all sites |
| 87 |
if ( is_multisite() ) { |
| 88 |
// Get all blog IDs via the core API (avoids a direct, uncached DB query). |
| 89 |
$ultimate_cursor_blog_ids = get_sites( |
| 90 |
array( |
| 91 |
'fields' => 'ids', |
| 92 |
'number' => 0, |
| 93 |
) |
| 94 |
); |
| 95 |
|
| 96 |
foreach ( $ultimate_cursor_blog_ids as $ultimate_cursor_blog_id ) { |
| 97 |
switch_to_blog( $ultimate_cursor_blog_id ); |
| 98 |
ultimate_cursor_delete_site_data(); |
| 99 |
restore_current_blog(); |
| 100 |
} |
| 101 |
} |
| 102 |
|
| 103 |
// Note: We don't delete posts created by the plugin, as those might be |
| 104 |
// important data the user wants to keep. |
| 105 |
|