` of early 0.4 builds; pages the owner made and assigned are * kept) · options `aooshop_templates` / `aooshop_templates_drafted` · scheduled events · rewrite rules (flushed without ours). * role `aooshop_manager` + caps `aooshop_view_*` (users of the role become Editors) · * Kept on purpose: nav menu items converted to custom links (class-menu-convert.php) and their `_aooshop_menu_backup` * meta; posts converted by class-content-convert.php and their `_aooshop_content_backup` meta (`_aoo_menu_backup` / * `_aoo_content_backup` before the rename). * Nothing is removed while an earlier copy (`wp-aoocommerce/` or `aoocommerce/`) is still active — it shares the data. * * @package AooShop */ defined( 'WP_UNINSTALL_PLUGIN' ) || exit; $aooshop_settings = get_option( 'aooshop_settings', false ); if ( false === $aooshop_settings ) { $aooshop_settings = get_option( 'aoo_shop_settings', array() ); // 0.7.0 data that was never upgraded. } if ( is_array( $aooshop_settings ) && ! empty( $aooshop_settings['keep_data'] ) ) { return; } // An earlier copy of this plugin (same `aooshop_*` data) is still active — it keeps using the data, so keep it all. $aooshop_network = is_multisite() ? (array) get_site_option( 'active_sitewide_plugins', array() ) : array(); foreach ( array( 'wp-aoocommerce/wp-aoocommerce.php', 'aoocommerce/aoocommerce.php' ) as $aooshop_legacy ) { if ( file_exists( WP_PLUGIN_DIR . '/' . $aooshop_legacy ) && ( in_array( $aooshop_legacy, (array) get_option( 'active_plugins', array() ), true ) || isset( $aooshop_network[ $aooshop_legacy ] ) ) ) { return; } } global $wpdb; // Role "ผู้จัดการร้าน (AooCommerce)" (its users become Editors) + the view caps on every role / user. require_once __DIR__ . '/includes/class-roles.php'; AooShop_Roles::uninstall(); // Cached pages listed in the index (object-cache sites keep transients outside wp_options). $aooshop_index = get_option( 'aooshop_cache_index', array() ); if ( is_array( $aooshop_index ) ) { foreach ( array_keys( $aooshop_index ) as $aooshop_key ) { delete_transient( 'aooshop_page_' . $aooshop_key ); delete_transient( 'aooshop_stale_' . $aooshop_key ); } } foreach ( array( 'aooshop_api_down', 'aooshop_sitemap', 'aooshop_sitemap_stale', 'aooshop_llms', 'aooshop_llms_stale', 'aooshop_card_posts', 'aooshop_rd_lookups', 'aooshop_purge_refresh', 'aooshop_ping_on_save', 'aooshop_ping_on_all', 'aooshop_facets_na' ) as $aooshop_transient ) { delete_transient( $aooshop_transient ); } // Template page. $aooshop_tpl = (int) get_option( 'aooshop_template_id', 0 ); if ( $aooshop_tpl ) { wp_delete_post( $aooshop_tpl, true ); } // Per-type template pages (0.4): only the samples the plugin created — assigned or not, any status. $aooshop_samples = get_posts( array( 'post_type' => 'page', 'post_status' => 'any', 'meta_key' => '_aooshop_sample', // phpcs:ignore WordPress.DB.SlowDBQuery 'posts_per_page' => -1, 'fields' => 'ids', ) ); $aooshop_assigned = get_option( 'aooshop_templates', array() ); foreach ( ( is_array( $aooshop_assigned ) ? $aooshop_assigned : array() ) as $aooshop_type => $aooshop_id ) { $aooshop_id = absint( $aooshop_id ); if ( $aooshop_id && 'aoo-template-' . sanitize_key( (string) $aooshop_type ) === get_post_field( 'post_name', $aooshop_id ) ) { $aooshop_samples[] = $aooshop_id; // Sample made before the marker meta existed. } } foreach ( array_unique( array_map( 'intval', $aooshop_samples ) ) as $aooshop_id ) { wp_delete_post( $aooshop_id, true ); } delete_option( 'aooshop_templates' ); delete_option( 'aooshop_templates_drafted' ); // Redirects table (+ its earlier names `aoo_shop_redirects` / `aoo_redirects`, in case they were never migrated). $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}aooshop_redirects" ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery, WordPress.DB.PreparedSQL.InterpolatedNotPrepared $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}aoo_shop_redirects" ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery, WordPress.DB.PreparedSQL.InterpolatedNotPrepared $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}aoo_redirects" ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery, WordPress.DB.PreparedSQL.InterpolatedNotPrepared // Every option + transient row of the plugin still in wp_options (incl. ones not listed above, e.g. rate limits). $aooshop_like = array( $wpdb->esc_like( 'aooshop_' ) . '%', $wpdb->esc_like( '_transient_aooshop_' ) . '%', $wpdb->esc_like( '_transient_timeout_aooshop_' ) . '%', // Options + transients of 0.7.0 before the prefix change (`aoo_shop_*`), in case the upgrade never ran. $wpdb->esc_like( 'aoo_shop_' ) . '%', $wpdb->esc_like( '_transient_aoo_shop_' ) . '%', $wpdb->esc_like( '_transient_timeout_aoo_shop_' ) . '%', // Page cache of 0.1–0.6 (`aoo_page_*` / `aoo_stale_*`); 0.7+ uses `aooshop_page_*` / `aooshop_stale_*` (covered above). $wpdb->esc_like( '_transient_aoo_page_' ) . '%', $wpdb->esc_like( '_transient_timeout_aoo_page_' ) . '%', $wpdb->esc_like( '_transient_aoo_stale_' ) . '%', $wpdb->esc_like( '_transient_timeout_aoo_stale_' ) . '%', ); foreach ( $aooshop_like as $aooshop_pattern ) { $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->options} WHERE option_name LIKE %s", $aooshop_pattern ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery } wp_cache_flush(); // Self-hosted embed CSS copies (0.6.2) — wp-content/uploads/aoo-shop/. $aooshop_up = wp_upload_dir( null, false ); if ( empty( $aooshop_up['error'] ) && ! empty( $aooshop_up['basedir'] ) ) { $aooshop_dir = trailingslashit( $aooshop_up['basedir'] ) . 'aoo-shop'; foreach ( (array) glob( $aooshop_dir . '/storefront-embed-*.css' ) as $aooshop_file ) { wp_delete_file( $aooshop_file ); } require_once ABSPATH . 'wp-admin/includes/file.php'; global $wp_filesystem; if ( 'direct' === get_filesystem_method( array(), $aooshop_up['basedir'] ) && WP_Filesystem( false, $aooshop_up['basedir'] ) && $wp_filesystem ) { $wp_filesystem->rmdir( $aooshop_dir ); // Not recursive — only when empty. } } foreach ( array( 'aooshop_refresh_page', 'aooshop_daily_ping', 'aooshop_refresh_remote', 'aooshop_cache_css', 'aoo_shop_refresh_page', 'aoo_shop_daily_ping', 'aoo_shop_refresh_remote', 'aoo_shop_cache_css' ) as $aooshop_hook ) { wp_unschedule_hook( $aooshop_hook ); } // Rules were removed on deactivation already; flush once more without them (in case of a direct uninstall). flush_rewrite_rules();