ID; // Update with SPA shortcode if needed if (!has_shortcode($existing_page->post_content, 'woonoow_spa')) { update_post_meta($spa_page_id, '_woonoow_original_content', $existing_page->post_content); wp_update_post([ 'ID' => $spa_page_id, 'post_content' => '[woonoow_spa]', ]); } } else { // Create new SPA page $spa_page_id = wp_insert_post([ 'post_title' => 'Store', 'post_content' => '[woonoow_spa]', 'post_status' => 'publish', 'post_type' => 'page', 'post_author' => get_current_user_id() ?: 1, 'comment_status' => 'closed', ]); } // Save SPA page ID if ($spa_page_id && !is_wp_error($spa_page_id)) { update_option('woonoow_store_page_id', $spa_page_id); // Also set it in appearance settings $appearance_settings = get_option('woonoow_appearance_settings', []); if (!isset($appearance_settings['general'])) { $appearance_settings['general'] = []; } $appearance_settings['general']['spa_page'] = $spa_page_id; update_option('woonoow_appearance_settings', $appearance_settings); } } /** * Run on plugin deactivation */ public static function deactivate() { // Restore original page content self::restore_original_content(); // Flush rewrite rules flush_rewrite_rules(); // Note: We don't delete pages on deactivation // Users might have content on those pages } /** * Restore original content to pages that were modified */ private static function restore_original_content() { $page_keys = ['shop', 'cart', 'checkout', 'account']; foreach ($page_keys as $key) { $page_id = get_option('woonoow_' . $key . '_page_id'); if ($page_id) { $original_content = get_post_meta($page_id, '_woonoow_original_content', true); if ($original_content) { // Restore original content wp_update_post([ 'ID' => $page_id, 'post_content' => $original_content, ]); // Remove backup delete_post_meta($page_id, '_woonoow_original_content'); } } } } /** * Run on plugin uninstall */ public static function uninstall() { // Only delete if user explicitly wants to remove all data if (get_option('woonoow_remove_data_on_uninstall', false)) { self::delete_pages(); self::delete_options(); } } /** * Delete WooNooW pages */ private static function delete_pages() { $page_keys = ['shop', 'cart', 'checkout', 'account']; foreach ($page_keys as $key) { $page_id = get_option('woonoow_' . $key . '_page_id'); if ($page_id) { wp_delete_post($page_id, true); // Force delete delete_option('woonoow_' . $key . '_page_id'); } } } /** * Delete WooNooW options */ private static function delete_options() { global $wpdb; // Delete all options starting with 'woonoow_' $wpdb->query("DELETE FROM {$wpdb->options} WHERE option_name LIKE 'woonoow_%'"); } }