Forráskód Böngészése

Fix JS event handler not binding for Clear Media form

- Bump version to 1.5.1 to force browser cache bust for JS/CSS
- Wrap each form init in try-catch (safeInit) so one form's JS error
  cannot prevent other forms from initializing
- Log version in console to verify correct JS is loaded
- Guard against undefined studiouWcpcm object

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Dalibor Votruba 3 hónapja
szülő
commit
2f77033f4e

+ 26 - 53
studiou-wc-product-cat-manage/assets/js/admin.js

@@ -4,66 +4,39 @@
 (function($) {
     'use strict';
     
+    // Safe init wrapper - prevents one form's error from breaking others
+    function safeInit(name, selector, initFn) {
+        try {
+            if ($(selector).length) {
+                console.log('STUDIOU WC: ' + name + ' found, initializing');
+                initFn();
+            }
+        } catch (e) {
+            console.error('STUDIOU WC: Error initializing ' + name + ':', e);
+        }
+    }
+
     // Initialize admin scripts
     $(document).ready(function() {
         // Debug: Log that script is loaded
-        console.log('STUDIOU WC: Admin script loaded');
-        console.log('STUDIOU WC: studiouWcpcm object:', studiouWcpcm);
-        
-        // Import form handling
-        if ($('#studiou-wcpcm-import-form').length) {
-            console.log('STUDIOU WC: Import form found');
-            initImportForm();
-        }
-        
-        // Export form handling
-        if ($('#studiou-wcpcm-export-form').length) {
-            console.log('STUDIOU WC: Export form found');
-            initExportForm();
-        }
-        
-        // Move products form handling
-        if ($('#studiou-wcpcm-move-form').length) {
-            console.log('STUDIOU WC: Move form found');
-            initMoveForm();
-        } else {
-            console.log('STUDIOU WC: Move form NOT found');
-        }
-        
-        // Batch description form handling
-        if ($('#studiou-wcpcm-batch-description-form').length) {
-            console.log('STUDIOU WC: Batch description form found');
-            initBatchDescriptionForm();
-        }
-
-        // Delete products form handling
-        if ($('#studiou-wcpcm-delete-products-form').length) {
-            console.log('STUDIOU WC: Delete products form found');
-            initDeleteProductsForm();
-        }
+        console.log('STUDIOU WC: Admin script loaded v1.5.1');
 
-        // Clear media categories form handling
-        if ($('#studiou-wcpcm-clear-media-form').length) {
-            console.log('STUDIOU WC: Clear media form found');
-            initClearMediaForm();
+        if (typeof studiouWcpcm === 'undefined') {
+            console.error('STUDIOU WC: studiouWcpcm object is NOT defined - AJAX will not work');
+            return;
         }
 
-        // Sample CSV download handler
-        if ($('#studiou-wcpcm-download-sample').length) {
-            initSampleDownload();
-        }
-
-        // Product import form handling
-        if ($('#studiou-wcpcm-product-import-form').length) {
-            console.log('STUDIOU WC: Product import form found');
-            initProductImportForm();
-        }
+        console.log('STUDIOU WC: studiouWcpcm object:', studiouWcpcm);
 
-        // Product export form handling
-        if ($('#studiou-wcpcm-product-export-form').length) {
-            console.log('STUDIOU WC: Product export form found');
-            initProductExportForm();
-        }
+        safeInit('Import form', '#studiou-wcpcm-import-form', initImportForm);
+        safeInit('Export form', '#studiou-wcpcm-export-form', initExportForm);
+        safeInit('Move form', '#studiou-wcpcm-move-form', initMoveForm);
+        safeInit('Batch description form', '#studiou-wcpcm-batch-description-form', initBatchDescriptionForm);
+        safeInit('Delete products form', '#studiou-wcpcm-delete-products-form', initDeleteProductsForm);
+        safeInit('Clear media form', '#studiou-wcpcm-clear-media-form', initClearMediaForm);
+        safeInit('Sample download', '#studiou-wcpcm-download-sample', initSampleDownload);
+        safeInit('Product import form', '#studiou-wcpcm-product-import-form', initProductImportForm);
+        safeInit('Product export form', '#studiou-wcpcm-product-export-form', initProductExportForm);
     });
     
     /**

+ 2 - 2
studiou-wc-product-cat-manage/studiou-wc-product-cat-manage.php

@@ -3,7 +3,7 @@
  * Plugin Name: QDR - Studiou WC Export/Import Product Categories
  * Plugin URI: https://www.quadarax.com/plugins/studiou-wc-product-cat-manage
  * Description: Allows batch import and export WooCommerce product categories and products
- * Version: 1.5.0
+ * Version: 1.5.1
  * Requires at least: 6.8.1
  * Requires PHP: 8.2
  * Author: Dalibor Votruba
@@ -23,7 +23,7 @@ if (!defined('WPINC')) {
 }
 
 // Define plugin constants
-if (!defined('STUDIOU_WCPCM_VERSION')) define('STUDIOU_WCPCM_VERSION', '1.5.0');
+if (!defined('STUDIOU_WCPCM_VERSION')) define('STUDIOU_WCPCM_VERSION', '1.5.1');
 if (!defined('STUDIOU_WCPCM_PLUGIN_DIR')) define('STUDIOU_WCPCM_PLUGIN_DIR', plugin_dir_path(__FILE__));
 if (!defined('STUDIOU_WCPCM_PLUGIN_URL')) define('STUDIOU_WCPCM_PLUGIN_URL', plugin_dir_url(__FILE__));
 if (!defined('STUDIOU_WCPCM_PLUGIN_BASENAME')) define('STUDIOU_WCPCM_PLUGIN_BASENAME', plugin_basename(__FILE__));