| 1 |
<?php |
| 2 |
/** |
| 3 |
* Uninstall script for Commerce7 for WordPress |
| 4 |
* |
| 5 |
* This file is executed when the plugin is uninstalled (deleted). |
| 6 |
* It removes all plugin data from the database. |
| 7 |
* |
| 8 |
* @package wp-commerce7 |
| 9 |
* @author Michael Bourne |
| 10 |
* @license GPL3 |
| 11 |
* @link https://ursa6.com |
| 12 |
* @since 1.5.5 |
| 13 |
*/ |
| 14 |
|
| 15 |
// If uninstall not called from WordPress, then exit. |
| 16 |
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { |
| 17 |
exit; |
| 18 |
} |
| 19 |
|
| 20 |
// Check user permissions |
| 21 |
if ( ! current_user_can( 'activate_plugins' ) ) { |
| 22 |
return; |
| 23 |
} |
| 24 |
|
| 25 |
// Remove plugin options |
| 26 |
delete_option( 'c7wp_settings' ); |
| 27 |
delete_option( 'c7wp_activation' ); |
| 28 |
|
| 29 |
// Remove transients |
| 30 |
delete_transient( 'c7wp_remote_notices' ); |
| 31 |
delete_transient( 'c7wp-admin-notice-pages' ); |
| 32 |
delete_transient( 'c7wp-admin-notice-pages-missing' ); |
| 33 |
|
| 34 |
// Remove callout transients (these have dynamic names) |
| 35 |
global $wpdb; |
| 36 |
$wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE '_transient_c7wp_%'" ); |
| 37 |
$wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE '_transient_timeout_c7wp_%'" ); |
| 38 |
|
| 39 |
// Remove user meta for dismissed notices |
| 40 |
$wpdb->query( "DELETE FROM {$wpdb->usermeta} WHERE meta_key LIKE 'c7wp_notice_dismissed_%'" ); |
| 41 |
|
| 42 |
// Clear scheduled cron jobs |
| 43 |
wp_clear_scheduled_hook( 'c7wp_fetch_remote_notices' ); |
| 44 |
|
| 45 |
// Optionally remove created pages (with user confirmation via filter) |
| 46 |
if ( apply_filters( 'c7wp_uninstall_remove_pages', false ) ) { |
| 47 |
$pages_to_remove = array( 'profile', 'collection', 'product', 'club', 'checkout', 'cart', 'reservation' ); |
| 48 |
|
| 49 |
foreach ( $pages_to_remove as $page_slug ) { |
| 50 |
$page_obj = get_page_by_path( $page_slug, OBJECT, 'page' ); |
| 51 |
if ( $page_obj ) { |
| 52 |
wp_delete_post( $page_obj->ID, true ); // true = force delete (bypass trash) |
| 53 |
} |
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
// Flush rewrite rules to clean up custom routes |
| 58 |
flush_rewrite_rules(); |
| 59 |
|