new CategoryExportModule($api, new CategoryExportMapper()), // Export categories to Aikanen (service groups) 'category_import' => new CategoryImportModule($api, new CategoryImportMapper(), new ProductImportMapper()), // Import categories (service groups) from Aikanen to Woo 'product_export' => new ProductExportModule($api, new ProductExportMapper()), // Export products from Woo to Aikanen 'product_import' => new ProductImportModule($api, new ProductImportMapper()), // Import products from Aikanen to Woo 'stock_sync' => new StockSyncModule($api), // Sync stocks between WooCommerce and Aikanen ]; if (is_admin()) { // Register settings page only for admin (new SettingsPage($modules))->register(); } foreach ($modules as $module) { $module->boot(); if ($module->isEnabled()) { // Boot enabled modules $module->register(); } } }); // Add settings link to plugins page add_filter('plugin_action_links_' . plugin_basename(__FILE__), function (array $links): array { $links[] = '' . __('Settings', 'aikanen') . ''; return $links; }); // Clean up on plugin deactivation register_deactivation_hook(__FILE__, function () { // Remove scheduled actions from Action Scheduler as_unschedule_all_actions('aikanen_export_product'); as_unschedule_all_actions('aikanen_push_stock'); as_unschedule_all_actions('aikanen_stock_full_sync'); // Delete transients delete_transient('aikanen_connection_status'); delete_transient('aikanen_preview'); }); // Clean up on plugin uninstallation register_uninstall_hook(__FILE__, 'aikanen_uninstall'); function aikanen_uninstall(): void { // Clean up database entries delete_option('aikanen_api_token'); delete_option('aikanen_auto_export_category'); delete_option('aikanen_auto_export_product'); delete_option('aikanen_auto_import_category'); delete_option('aikanen_auto_import_product'); delete_option('aikanen_auto_stock_sync'); delete_option('aikanen_stock_full_sync_interval'); delete_option('aikanen_stock_source_of_truth'); delete_option('aikanen_vat_map'); delete_option('aikanen_webhook_secret'); foreach (['category_export', 'category_import', 'product_export', 'product_import', 'stock_sync'] as $key) { delete_option("aikanen_module_{$key}_enabled"); } // Cancel webhook orders from Aikanen $api = new ApiClient(get_option('aikanen_api_token', '')); $events = [ 'category_import' => ['service_group.created', 'service_group.updated', 'service_group.services_attached', 'service_group.services_detached'], 'product_import' => ['service.created', 'service.updated'], 'stock_sync' => ['stock.updated'], ]; foreach ($events as $key => $moduleEvents) { foreach ($moduleEvents as $event) { $id = get_option("aikanen_webhook_id_{$key}_{$event}"); if ($id) { try { $api->delete("/webhooks/{$id}"); } catch (\Exception $e) {} delete_option("aikanen_webhook_id_{$key}_{$event}"); } } } // Remove _aikanen_service_id from all products $posts = get_posts(['post_type' => 'product', 'meta_key' => '_aikanen_service_id', 'fields' => 'ids', 'nopaging' => true]); foreach ($posts as $id) { delete_post_meta($id, '_aikanen_service_id'); delete_post_meta($id, '_aikanen_last_synced'); } // Remove _aikanen_group_id from all terms $terms = get_terms(['taxonomy' => 'product_cat', 'hide_empty' => false, 'meta_query' => [['key' => '_aikanen_group_id', 'compare' => 'EXISTS']]]); foreach ($terms as $term) { delete_term_meta($term->term_id, '_aikanen_group_id'); } }