Explorar o código

Add Clear Media Categories feature — v1.4.0 -> v1.5.0

New "Clear Media Categories" operation in Category Manipulations page
to permanently delete all media files from selected media categories
with batch processing (10 files/batch), real-time progress bar,
confirmation dialog, and comprehensive deletion statistics.
Auto-detects media category taxonomy (media_category,
attachment_category, media-category) with graceful fallback.

Updated all documentation (CLAUDE.md, readme.md) and translations
(EN .po, CS .po) including previously missing v1.3.0 strings.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Dalibor Votruba hai 3 meses
pai
achega
88655ad7cf

+ 22 - 1
studiou-wc-product-cat-manage/CLAUDE.md

@@ -6,7 +6,7 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
 
 **QDR - Studiou WC Export/Import Product Categories** is a WordPress plugin that extends WooCommerce to provide batch export/import functionality for both product categories and products, along with category manipulation tools.
 
-**Current Version:** 1.4.0
+**Current Version:** 1.5.0
 
 ## Requirements
 
@@ -51,8 +51,10 @@ The plugin follows a modular class-based architecture:
   - Move products between categories (removes from source, adds to target)
   - Batch description updates for multiple categories
   - Delete products in category (permanently deletes products and variants)
+  - Clear Media Categories (permanently deletes media files from media categories) (NEW in v1.5)
   - Uses direct database queries for reliable product detection
   - Batch processing for delete operations (10 products per batch)
+  - Auto-detects media category taxonomy (media_category, attachment_category, media-category)
 
 - **class-studiou-wc-product-manage-product-db.php** - Product database operations (NEW in v1.4)
   - Retrieves product categories with hierarchy
@@ -91,6 +93,7 @@ The plugin follows a modular class-based architecture:
   - Move products between categories (two dropdowns + "Do" button)
   - Batch description between categories (checkbox list + textarea + "Do" button)
   - Delete products in category (checkbox list + "Delete" button + progress bar)
+  - Clear Media Categories (checkbox list + "Delete" button + progress bar) (NEW in v1.5)
 - **product-import.php** - Product import page UI (NEW in v1.4)
   - File upload for CSV import
   - Progress bar for import operations
@@ -198,6 +201,7 @@ All pages are added under **Products** menu:
   - Move products between categories
   - Batch description between categories
   - Delete products in category
+  - Clear Media Categories (NEW in v1.5)
 - **Product Import (slug: `studiou-product-import`)** - NEW in v1.4
 - **Product Export (slug: `studiou-product-export`)** - NEW in v1.4
 
@@ -259,6 +263,21 @@ All pages are added under **Products** menu:
   6. Parent reference validation
   7. Variation price requirement
 
+### Clear Media Categories Operations (NEW in v1.5)
+- Test with media category plugin installed (e.g., Media Library Categories)
+- Test without media category plugin installed (should show graceful fallback message)
+- Test deletion with:
+  - Single media category selected
+  - Multiple media categories selected
+  - Empty media categories
+  - Large numbers of media files (test batch processing)
+  - Check All/Uncheck All functionality
+- Verify confirmation dialog appears before deletion
+- Verify progress bar updates correctly during batch deletion
+- Verify media files are actually removed from disk
+- Verify deletion statistics are accurate
+- Test with media files used as product images (verify WooCommerce product references are handled)
+
 ### General
 - Verify translations are properly loaded (English/Czech)
 - Verify progress bars update correctly
@@ -276,6 +295,8 @@ The plugin registers the following AJAX actions:
 4. **studiou_wcpcm_batch_description** - Updates descriptions for multiple categories
 5. **studiou_wcpcm_delete_products** - Initial request to get product IDs for deletion
 6. **studiou_wcpcm_delete_products_batch** - Processes product deletion in batches
+7. **studiou_wcpcm_clear_media** - Initial request to get media IDs for deletion (NEW in v1.5)
+8. **studiou_wcpcm_clear_media_batch** - Processes media deletion in batches (NEW in v1.5)
 
 ### Product Operations (NEW in v1.4)
 7. **studiou_wcpcm_product_import_parse** - Parses CSV file and stores in transient (Step 1)

+ 12 - 5
studiou-wc-product-cat-manage/assets/css/admin.css

@@ -206,7 +206,9 @@
 
 /* Progress bar styling */
 .studiou-wcpcm-delete-progress,
-.studiou-wcpcm-delete-results {
+.studiou-wcpcm-delete-results,
+.studiou-wcpcm-clear-media-progress,
+.studiou-wcpcm-clear-media-results {
     margin-top: 30px;
     padding: 20px;
     background: #f9f9f9;
@@ -215,7 +217,9 @@
 }
 
 .studiou-wcpcm-delete-progress h3,
-.studiou-wcpcm-delete-results h3 {
+.studiou-wcpcm-delete-results h3,
+.studiou-wcpcm-clear-media-progress h3,
+.studiou-wcpcm-clear-media-results h3 {
     margin-top: 0;
     margin-bottom: 15px;
 }
@@ -255,16 +259,19 @@
     margin-top: 10px;
 }
 
-.studiou-wcpcm-delete-results ul {
+.studiou-wcpcm-delete-results ul,
+.studiou-wcpcm-clear-media-results ul {
     list-style: none;
     padding-left: 0;
 }
 
-.studiou-wcpcm-delete-results ul li {
+.studiou-wcpcm-delete-results ul li,
+.studiou-wcpcm-clear-media-results ul li {
     padding: 8px 0;
     border-bottom: 1px solid #e0e0e0;
 }
 
-.studiou-wcpcm-delete-results ul li:last-child {
+.studiou-wcpcm-delete-results ul li:last-child,
+.studiou-wcpcm-clear-media-results ul li:last-child {
     border-bottom: none;
 }

+ 238 - 0
studiou-wc-product-cat-manage/assets/js/admin.js

@@ -42,6 +42,12 @@
             initDeleteProductsForm();
         }
 
+        // Clear media categories form handling
+        if ($('#studiou-wcpcm-clear-media-form').length) {
+            console.log('STUDIOU WC: Clear media form found');
+            initClearMediaForm();
+        }
+
         // Sample CSV download handler
         if ($('#studiou-wcpcm-download-sample').length) {
             initSampleDownload();
@@ -623,6 +629,237 @@
         $('#studiou-wcpcm-delete-progress-bar').attr('data-progress', percentage + '%');
     }
 
+    /**
+     * Initialize clear media categories form
+     */
+    function initClearMediaForm() {
+        console.log('STUDIOU WC: Initializing clear media form handlers');
+
+        // Check all button handler
+        $('#studiou-wcpcm-clear-media-check-all').on('click', function(e) {
+            e.preventDefault();
+            console.log('STUDIOU WC: Clear media check all button clicked');
+            $('#clear_media_categories_list input[type="checkbox"]').prop('checked', true);
+        });
+
+        // Uncheck all button handler
+        $('#studiou-wcpcm-clear-media-uncheck-all').on('click', function(e) {
+            e.preventDefault();
+            console.log('STUDIOU WC: Clear media uncheck all button clicked');
+            $('#clear_media_categories_list input[type="checkbox"]').prop('checked', false);
+        });
+
+        // Form submit handler
+        $('#studiou-wcpcm-clear-media-form').on('submit', function(e) {
+            e.preventDefault();
+
+            console.log('STUDIOU WC: Clear media form submitted');
+
+            // Get selected categories
+            var selectedCategories = [];
+            $('#clear_media_categories_list input[type="checkbox"]:checked').each(function() {
+                selectedCategories.push($(this).val());
+            });
+
+            console.log('STUDIOU WC: Selected media categories:', selectedCategories);
+
+            // Validate input
+            if (selectedCategories.length === 0) {
+                console.log('STUDIOU WC: No media categories selected');
+                showNotice('error', studiouWcpcm.i18n.selectAtLeastOneCategory || 'Please select at least one category');
+                return;
+            }
+
+            // Confirm deletion
+            if (!confirm(studiouWcpcm.i18n.confirmClearMedia || 'Are you sure you want to permanently delete ALL media files in the selected media categories? This action cannot be undone!')) {
+                console.log('STUDIOU WC: User cancelled clear media');
+                return;
+            }
+
+            // Show spinner
+            var $submitBtn = $(this).find('#studiou-wcpcm-clear-media-button');
+            var $spinner = $(this).find('.spinner');
+
+            $submitBtn.prop('disabled', true);
+            $spinner.css('visibility', 'visible');
+
+            // Clear previous notices
+            $('.studiou-wcpcm-notice-area').empty();
+
+            // Hide results, show progress
+            $('.studiou-wcpcm-clear-media-results').hide();
+            $('.studiou-wcpcm-clear-media-progress').show();
+            $('#studiou-wcpcm-clear-media-progress-text').text('Initializing...');
+            updateClearMediaProgressBar(0);
+
+            // Send AJAX request to get media IDs
+            $.ajax({
+                url: studiouWcpcm.ajaxUrl,
+                type: 'POST',
+                data: {
+                    action: 'studiou_wcpcm_clear_media',
+                    media_categories: selectedCategories,
+                    nonce: studiouWcpcm.nonce
+                },
+                success: function(response) {
+                    console.log('STUDIOU WC: Clear media AJAX response:', response);
+
+                    if (response.success) {
+                        var mediaIds = response.data.media_ids;
+                        var totalCount = response.data.total_count;
+
+                        console.log('STUDIOU WC: Total media files to delete:', totalCount);
+
+                        if (totalCount === 0) {
+                            showNotice('success', studiouWcpcm.i18n.noMediaFound || 'No media files found in selected categories');
+                            $('.studiou-wcpcm-clear-media-progress').hide();
+                            $submitBtn.prop('disabled', false);
+                            $spinner.css('visibility', 'hidden');
+                            return;
+                        }
+
+                        // Process media in batches
+                        processMediaDeletionBatches(mediaIds, totalCount, $submitBtn, $spinner);
+
+                    } else {
+                        showNotice('error', response.data.message);
+                        $('.studiou-wcpcm-clear-media-progress').hide();
+                        $submitBtn.prop('disabled', false);
+                        $spinner.css('visibility', 'hidden');
+                    }
+                },
+                error: function(xhr, status, error) {
+                    console.error('STUDIOU WC: Clear media AJAX error:', status, error);
+                    console.error('STUDIOU WC: Response text:', xhr.responseText);
+                    showNotice('error', (studiouWcpcm.i18n.clearMediaError || 'Clear media operation error') + ': ' + error);
+                    $('.studiou-wcpcm-clear-media-progress').hide();
+                    $submitBtn.prop('disabled', false);
+                    $spinner.css('visibility', 'hidden');
+                }
+            });
+        });
+    }
+
+    /**
+     * Process media deletion in batches
+     */
+    function processMediaDeletionBatches(mediaIds, totalCount, $submitBtn, $spinner) {
+        var batchSize = 10;
+        var batches = [];
+        var totalDeleted = 0;
+        var totalFailed = 0;
+        var failedMedia = [];
+
+        // Split media into batches
+        for (var i = 0; i < mediaIds.length; i += batchSize) {
+            batches.push(mediaIds.slice(i, i + batchSize));
+        }
+
+        console.log('STUDIOU WC: Processing ' + batches.length + ' batches of media files');
+
+        var currentBatch = 0;
+
+        function processBatch() {
+            if (currentBatch >= batches.length) {
+                console.log('STUDIOU WC: All media batches completed');
+                onMediaDeletionComplete(totalDeleted, totalFailed, failedMedia, $submitBtn, $spinner);
+                return;
+            }
+
+            var batch = batches[currentBatch];
+            var progress = Math.round((currentBatch / batches.length) * 100);
+
+            $('#studiou-wcpcm-clear-media-progress-text').text(
+                'Deleting media files... ' + (currentBatch * batchSize) + ' of ' + totalCount + ' processed'
+            );
+            updateClearMediaProgressBar(progress);
+
+            $.ajax({
+                url: studiouWcpcm.ajaxUrl,
+                type: 'POST',
+                data: {
+                    action: 'studiou_wcpcm_clear_media_batch',
+                    media_ids: batch,
+                    nonce: studiouWcpcm.nonce
+                },
+                success: function(response) {
+                    if (response.success) {
+                        totalDeleted += response.data.deleted_count;
+                        totalFailed += response.data.failed_count;
+                        failedMedia = failedMedia.concat(response.data.failed_media);
+
+                        console.log('STUDIOU WC: Media batch ' + currentBatch + ' completed - Deleted: ' +
+                            response.data.deleted_count + ', Failed: ' + response.data.failed_count);
+
+                        currentBatch++;
+                        processBatch();
+                    } else {
+                        showNotice('error', response.data.message);
+                        $('.studiou-wcpcm-clear-media-progress').hide();
+                        $submitBtn.prop('disabled', false);
+                        $spinner.css('visibility', 'hidden');
+                    }
+                },
+                error: function(xhr, status, error) {
+                    console.error('STUDIOU WC: Media batch delete AJAX error:', status, error);
+                    showNotice('error', 'Error deleting media batch: ' + error);
+                    $('.studiou-wcpcm-clear-media-progress').hide();
+                    $submitBtn.prop('disabled', false);
+                    $spinner.css('visibility', 'hidden');
+                }
+            });
+        }
+
+        processBatch();
+    }
+
+    /**
+     * Handle media deletion completion
+     */
+    function onMediaDeletionComplete(totalDeleted, totalFailed, failedMedia, $submitBtn, $spinner) {
+        updateClearMediaProgressBar(100);
+        $('#studiou-wcpcm-clear-media-progress-text').text('Deletion complete!');
+
+        var message = '<p><strong>Deletion Summary:</strong></p>';
+        message += '<ul>';
+        message += '<li>Total media files deleted: ' + totalDeleted + '</li>';
+        if (totalFailed > 0) {
+            message += '<li>Failed to delete: ' + totalFailed + '</li>';
+            if (failedMedia.length > 0) {
+                message += '<li>Failed media IDs: ' + failedMedia.join(', ') + '</li>';
+            }
+        }
+        message += '</ul>';
+
+        $('#studiou-wcpcm-clear-media-message').html(message);
+        $('.studiou-wcpcm-clear-media-results').show();
+
+        setTimeout(function() {
+            $('.studiou-wcpcm-clear-media-progress').fadeOut();
+        }, 2000);
+
+        if (totalDeleted > 0) {
+            showNotice('success', (studiouWcpcm.i18n.clearMediaSuccess || 'Successfully deleted') + ' ' + totalDeleted + ' media files');
+
+            setTimeout(function() {
+                location.reload();
+            }, 3000);
+        } else {
+            showNotice('error', studiouWcpcm.i18n.clearMediaError || 'Failed to delete any media files');
+        }
+
+        $submitBtn.prop('disabled', false);
+        $spinner.css('visibility', 'hidden');
+    }
+
+    /**
+     * Update clear media progress bar
+     */
+    function updateClearMediaProgressBar(percentage) {
+        $('#studiou-wcpcm-clear-media-progress-bar').css('width', percentage + '%');
+        $('#studiou-wcpcm-clear-media-progress-bar').attr('data-progress', percentage + '%');
+    }
+
     /**
      * Show notice message
      *
@@ -959,6 +1196,7 @@
         console.log('STUDIOU WC: Delete products form exists:', $('#studiou-wcpcm-delete-products-form').length > 0);
         console.log('STUDIOU WC: Product import form exists:', $('#studiou-wcpcm-product-import-form').length > 0);
         console.log('STUDIOU WC: Product export form exists:', $('#studiou-wcpcm-product-export-form').length > 0);
+        console.log('STUDIOU WC: Clear media form exists:', $('#studiou-wcpcm-clear-media-form').length > 0);
     });
 
 })(jQuery);

+ 340 - 1
studiou-wc-product-cat-manage/includes/class-studiou-wc-product-cat-manage-manipulator.php

@@ -36,13 +36,15 @@ class Studiou_WC_Product_Cat_Manage_Manipulator {
         add_action('wp_ajax_studiou_wcpcm_batch_description', array($this, 'handle_batch_description_ajax'));
         add_action('wp_ajax_studiou_wcpcm_delete_products', array($this, 'handle_delete_products_ajax'));
         add_action('wp_ajax_studiou_wcpcm_delete_products_batch', array($this, 'handle_delete_products_batch_ajax'));
+        add_action('wp_ajax_studiou_wcpcm_clear_media', array($this, 'handle_clear_media_ajax'));
+        add_action('wp_ajax_studiou_wcpcm_clear_media_batch', array($this, 'handle_clear_media_batch_ajax'));
 
         // Add a test AJAX handler to verify AJAX is working
         add_action('wp_ajax_studiou_wcpcm_test', array($this, 'handle_test_ajax'));
 
         // Debug: Log that the handler is being registered
         if (defined('WP_DEBUG') && WP_DEBUG) {
-            error_log('STUDIOU WC: AJAX handlers registered - move_products, batch_description, and delete_products');
+            error_log('STUDIOU WC: AJAX handlers registered - move_products, batch_description, delete_products, and clear_media');
         }
     }
     
@@ -854,4 +856,341 @@ class Studiou_WC_Product_Cat_Manage_Manipulator {
             'failed_products' => $failed_products
         );
     }
+
+    /**
+     * Get all media categories with file counts for select lists
+     *
+     * @return array Array of media categories with ID, name, and file count
+     */
+    public function get_media_categories_with_counts() {
+        $taxonomy = $this->get_media_category_taxonomy();
+
+        if (!$taxonomy) {
+            return array();
+        }
+
+        $args = array(
+            'taxonomy' => $taxonomy,
+            'orderby' => 'name',
+            'hide_empty' => false,
+        );
+
+        $categories = get_terms($args);
+        $categories_with_counts = array();
+
+        if (!is_wp_error($categories)) {
+            foreach ($categories as $category) {
+                $file_count = $this->get_media_category_file_count($category->term_id, $taxonomy);
+
+                $categories_with_counts[] = array(
+                    'id' => $category->term_id,
+                    'name' => $category->name,
+                    'count' => $file_count,
+                    'display_name' => sprintf('%s (%d %s)', $category->name, $file_count, __('files', 'studiou-wc-product-cat-manage'))
+                );
+            }
+        }
+
+        return $categories_with_counts;
+    }
+
+    /**
+     * Get the media category taxonomy name
+     *
+     * Checks for common media category taxonomies used by popular plugins
+     *
+     * @return string|false Taxonomy name or false if none found
+     */
+    private function get_media_category_taxonomy() {
+        $possible_taxonomies = array(
+            'media_category',
+            'attachment_category',
+            'media-category',
+        );
+
+        foreach ($possible_taxonomies as $taxonomy) {
+            if (taxonomy_exists($taxonomy)) {
+                return $taxonomy;
+            }
+        }
+
+        return false;
+    }
+
+    /**
+     * Get file count for a media category
+     *
+     * @param int $category_id Category term ID
+     * @param string $taxonomy Taxonomy name
+     * @return int File count
+     */
+    private function get_media_category_file_count($category_id, $taxonomy) {
+        global $wpdb;
+
+        $sql = "
+            SELECT COUNT(DISTINCT p.ID)
+            FROM {$wpdb->posts} p
+            INNER JOIN {$wpdb->term_relationships} tr ON p.ID = tr.object_id
+            INNER JOIN {$wpdb->term_taxonomy} tt ON tr.term_taxonomy_id = tt.term_taxonomy_id
+            WHERE tt.term_id = %d
+            AND tt.taxonomy = %s
+            AND p.post_type = 'attachment'
+        ";
+
+        $count = $wpdb->get_var($wpdb->prepare($sql, $category_id, $taxonomy));
+
+        return intval($count);
+    }
+
+    /**
+     * Get all media IDs from multiple media categories
+     *
+     * @param array $category_ids Array of category term IDs
+     * @return array Array of unique attachment IDs
+     */
+    private function get_media_from_categories($category_ids) {
+        global $wpdb;
+
+        $taxonomy = $this->get_media_category_taxonomy();
+
+        if (!$taxonomy || empty($category_ids)) {
+            return array();
+        }
+
+        $placeholders = implode(',', array_fill(0, count($category_ids), '%d'));
+
+        $sql = "
+            SELECT DISTINCT p.ID
+            FROM {$wpdb->posts} p
+            INNER JOIN {$wpdb->term_relationships} tr ON p.ID = tr.object_id
+            INNER JOIN {$wpdb->term_taxonomy} tt ON tr.term_taxonomy_id = tt.term_taxonomy_id
+            WHERE tt.term_id IN ($placeholders)
+            AND tt.taxonomy = %s
+            AND p.post_type = 'attachment'
+        ";
+
+        $params = array_merge($category_ids, array($taxonomy));
+        $media = $wpdb->get_col($wpdb->prepare($sql, $params));
+
+        if (defined('WP_DEBUG') && WP_DEBUG) {
+            error_log('STUDIOU WC: Found ' . count($media) . ' media files in media categories ' . implode(', ', $category_ids));
+        }
+
+        return $media ? array_map('intval', $media) : array();
+    }
+
+    /**
+     * Delete a batch of media files permanently
+     *
+     * @param array $media_ids Array of attachment IDs to delete
+     * @return array Result with counts
+     */
+    private function delete_media_batch($media_ids) {
+        $deleted_count = 0;
+        $failed_count = 0;
+        $failed_media = array();
+
+        foreach ($media_ids as $media_id) {
+            try {
+                $attachment = get_post($media_id);
+
+                if (!$attachment || $attachment->post_type !== 'attachment') {
+                    $failed_count++;
+                    $failed_media[] = $media_id;
+                    if (defined('WP_DEBUG') && WP_DEBUG) {
+                        error_log('STUDIOU WC: Media file ' . $media_id . ' not found or not an attachment');
+                    }
+                    continue;
+                }
+
+                // Force delete attachment and its files from disk
+                $result = wp_delete_attachment($media_id, true);
+
+                if ($result) {
+                    $deleted_count++;
+                    if (defined('WP_DEBUG') && WP_DEBUG) {
+                        error_log('STUDIOU WC: Successfully deleted media file ' . $media_id);
+                    }
+                } else {
+                    $failed_count++;
+                    $failed_media[] = $media_id;
+                    if (defined('WP_DEBUG') && WP_DEBUG) {
+                        error_log('STUDIOU WC: Failed to delete media file ' . $media_id);
+                    }
+                }
+
+            } catch (Exception $e) {
+                $failed_count++;
+                $failed_media[] = $media_id;
+                if (defined('WP_DEBUG') && WP_DEBUG) {
+                    error_log('STUDIOU WC: Exception deleting media file ' . $media_id . ': ' . $e->getMessage());
+                }
+            }
+        }
+
+        return array(
+            'deleted_count' => $deleted_count,
+            'failed_count' => $failed_count,
+            'failed_media' => $failed_media
+        );
+    }
+
+    /**
+     * Handle AJAX clear media request (initial request to get media IDs)
+     */
+    public function handle_clear_media_ajax() {
+        while (ob_get_level()) {
+            ob_end_clean();
+        }
+
+        ob_start();
+
+        $original_error_reporting = error_reporting();
+        error_reporting(0);
+
+        if (defined('WP_DEBUG') && WP_DEBUG) {
+            error_log('STUDIOU WC: Clear media AJAX handler called');
+            error_log('STUDIOU WC: POST data: ' . print_r($_POST, true));
+        }
+
+        try {
+            if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'studiou-wcpcm-nonce')) {
+                wp_send_json_error(array(
+                    'message' => __('Security check failed', 'studiou-wc-product-cat-manage')
+                ));
+            }
+
+            if (!current_user_can('manage_woocommerce')) {
+                wp_send_json_error(array(
+                    'message' => __('You do not have sufficient permissions', 'studiou-wc-product-cat-manage')
+                ));
+            }
+
+            if (!isset($_POST['media_categories'])) {
+                wp_send_json_error(array(
+                    'message' => __('Missing required parameters', 'studiou-wc-product-cat-manage')
+                ));
+            }
+
+            $category_ids = array_map('intval', $_POST['media_categories']);
+
+            if (empty($category_ids)) {
+                wp_send_json_error(array(
+                    'message' => __('Please select at least one category', 'studiou-wc-product-cat-manage')
+                ));
+            }
+
+            $media_ids = $this->get_media_from_categories($category_ids);
+
+            if (defined('WP_DEBUG') && WP_DEBUG) {
+                error_log('STUDIOU WC: Found ' . count($media_ids) . ' media files to delete');
+            }
+
+            ob_clean();
+
+            wp_send_json_success(array(
+                'media_ids' => $media_ids,
+                'total_count' => count($media_ids),
+                'message' => sprintf(
+                    __('Found %d media files to delete', 'studiou-wc-product-cat-manage'),
+                    count($media_ids)
+                )
+            ));
+
+        } catch (Exception $e) {
+            if (defined('WP_DEBUG') && WP_DEBUG) {
+                error_log('STUDIOU WC: Clear media operation failed - ' . $e->getMessage());
+                error_log('STUDIOU WC: Exception trace: ' . $e->getTraceAsString());
+            }
+
+            ob_clean();
+
+            wp_send_json_error(array(
+                'message' => sprintf(
+                    __('Error during clear media operation: %s', 'studiou-wc-product-cat-manage'),
+                    $e->getMessage()
+                )
+            ));
+        } finally {
+            error_reporting($original_error_reporting);
+            ob_end_clean();
+        }
+    }
+
+    /**
+     * Handle AJAX clear media batch request (processes media in batches)
+     */
+    public function handle_clear_media_batch_ajax() {
+        while (ob_get_level()) {
+            ob_end_clean();
+        }
+
+        ob_start();
+
+        $original_error_reporting = error_reporting();
+        error_reporting(0);
+
+        if (defined('WP_DEBUG') && WP_DEBUG) {
+            error_log('STUDIOU WC: Clear media batch AJAX handler called');
+            error_log('STUDIOU WC: POST data: ' . print_r($_POST, true));
+        }
+
+        try {
+            if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'studiou-wcpcm-nonce')) {
+                wp_send_json_error(array(
+                    'message' => __('Security check failed', 'studiou-wc-product-cat-manage')
+                ));
+            }
+
+            if (!current_user_can('manage_woocommerce')) {
+                wp_send_json_error(array(
+                    'message' => __('You do not have sufficient permissions', 'studiou-wc-product-cat-manage')
+                ));
+            }
+
+            if (!isset($_POST['media_ids'])) {
+                wp_send_json_error(array(
+                    'message' => __('Missing required parameters', 'studiou-wc-product-cat-manage')
+                ));
+            }
+
+            $media_ids = array_map('intval', $_POST['media_ids']);
+
+            if (defined('WP_DEBUG') && WP_DEBUG) {
+                error_log('STUDIOU WC: Processing batch of ' . count($media_ids) . ' media files for deletion');
+            }
+
+            $result = $this->delete_media_batch($media_ids);
+
+            if (defined('WP_DEBUG') && WP_DEBUG) {
+                error_log('STUDIOU WC: Batch media deletion completed - Deleted: ' . $result['deleted_count'] . ', Failed: ' . $result['failed_count']);
+            }
+
+            ob_clean();
+
+            wp_send_json_success(array(
+                'deleted_count' => $result['deleted_count'],
+                'failed_count' => $result['failed_count'],
+                'failed_media' => $result['failed_media']
+            ));
+
+        } catch (Exception $e) {
+            if (defined('WP_DEBUG') && WP_DEBUG) {
+                error_log('STUDIOU WC: Clear media batch operation failed - ' . $e->getMessage());
+                error_log('STUDIOU WC: Exception trace: ' . $e->getTraceAsString());
+            }
+
+            ob_clean();
+
+            wp_send_json_error(array(
+                'message' => sprintf(
+                    __('Error during clear media batch operation: %s', 'studiou-wc-product-cat-manage'),
+                    $e->getMessage()
+                )
+            ));
+        } finally {
+            error_reporting($original_error_reporting);
+            ob_end_clean();
+        }
+    }
 }

+ 11 - 1
studiou-wc-product-cat-manage/instructions.txt

@@ -74,4 +74,14 @@ Plugin will have following features:
 				- iterate selected product categories.
 				- category in iteration will be set category field "Description"
 				- at the end of operation print out output information how many categories was set.
-	- all text will be translatable 
+	- all text will be translatable
+7. Implements following features: 
+	- in existing menu "Products" | "Category manipulations"
+		- In screen Category manipulations implements operation called "Clear Media Categories" in header to delete (permanently) all media files from selected media category selected.
+		- There will be listbox with checkboxes with Media Category list (in each items will be count of assigned files). Listbox will have client operations "check all", "uncheck all".
+		- The will be button "Delete" that start operation
+		- Real-time progress bar for deletion operations
+		- Batch processing for large-scale deletions (processes 10 medias at a time)		
+		- Comprehensive deletion statistics and error reporting
+		- Enhanced warning messages for destructive operations
+		- Improved user interface with confirmation dialogs

+ 147 - 3
studiou-wc-product-cat-manage/languages/studiou-wc-product-cat-manage-cs_CZ.po

@@ -3,10 +3,10 @@
 # This file is distributed under the same license as the QDR - Studiou WC Export/Import Product Categories package.
 msgid ""
 msgstr ""
-"Project-Id-Version: QDR - Studiou WC Export/Import Product Categories 1.2.1\n"
+"Project-Id-Version: QDR - Studiou WC Export/Import Product Categories 1.5.0\n"
 "Report-Msgid-Bugs-To: https://www.quadarax.com/plugins/studiou-wc-product-"
 "cat-manage\n"
-"POT-Creation-Date: 2025-05-15 12:00+0000\n"
+"POT-Creation-Date: 2026-04-01 12:00+0000\n"
 "PO-Revision-Date: 2025-05-15 12:04+0200\n"
 "Last-Translator: Dalibor Votruba <dvotruba@quadarax.com>\n"
 "Language-Team: Czech\n"
@@ -803,4 +803,148 @@ msgstr "Povolit recenze"
 
 #: views/product-export.php:108
 msgid "The exported file can be modified and re-imported using the Product Import feature."
-msgstr "Exportovaný soubor může být upraven a znovu importován pomocí funkce Import produktů."
+msgstr "Exportovaný soubor může být upraven a znovu importován pomocí funkce Import produktů."
+
+#. ==========================================
+#. Delete Products in Category (v1.3.0)
+#. ==========================================
+
+#: studiou-wc-product-cat-manage.php
+msgid "Delete operation successful"
+msgstr "Operace smazání úspěšná"
+
+#: studiou-wc-product-cat-manage.php
+msgid "Delete operation error"
+msgstr "Chyba operace smazání"
+
+#: studiou-wc-product-cat-manage.php
+msgid "Are you sure you want to permanently delete ALL products in the selected categories? This action cannot be undone!"
+msgstr "Opravdu chcete trvale smazat VŠECHNY produkty ve vybraných kategoriích? Tuto akci nelze vrátit zpět!"
+
+#: studiou-wc-product-cat-manage.php
+msgid "No products found in selected categories"
+msgstr "Ve vybraných kategoriích nebyly nalezeny žádné produkty"
+
+#: views/manipulations.php
+msgid "Delete products in category"
+msgstr "Smazat produkty v kategorii"
+
+#: views/manipulations.php
+msgid "This operation allows you to permanently delete all products and their variants from selected categories. This action cannot be undone!"
+msgstr "Tato operace umožňuje trvale smazat všechny produkty a jejich varianty z vybraných kategorií. Tuto akci nelze vrátit zpět!"
+
+#: views/manipulations.php
+msgid "Select the categories from which all products will be permanently deleted."
+msgstr "Vyberte kategorie, ze kterých budou všechny produkty trvale smazány."
+
+#: views/manipulations.php
+msgid "WARNING: This operation will permanently delete all products (including variants) in the selected categories. This action cannot be undone!"
+msgstr "VAROVÁNÍ: Tato operace trvale smaže všechny produkty (včetně variant) ve vybraných kategoriích. Tuto akci nelze vrátit zpět!"
+
+#: views/manipulations.php
+msgid "Delete"
+msgstr "Smazat"
+
+#: views/manipulations.php
+msgid "Deletion Progress"
+msgstr "Průběh mazání"
+
+#: views/manipulations.php
+msgid "Deletion Results"
+msgstr "Výsledky mazání"
+
+#: views/manipulations.php
+msgid "The delete products operation will permanently delete all products and variants from the selected categories. This action cannot be undone!"
+msgstr "Operace smazání produktů trvale smaže všechny produkty a varianty z vybraných kategorií. Tuto akci nelze vrátit zpět!"
+
+#: includes/class-studiou-wc-product-cat-manage-manipulator.php
+msgid "Found %d products to delete"
+msgstr "Nalezeno %d produktů ke smazání"
+
+#: includes/class-studiou-wc-product-cat-manage-manipulator.php
+msgid "Error during delete operation: %s"
+msgstr "Chyba během operace smazání: %s"
+
+#: includes/class-studiou-wc-product-cat-manage-manipulator.php
+msgid "Error during delete batch operation: %s"
+msgstr "Chyba během dávkové operace smazání: %s"
+
+#: studiou-wc-product-cat-manage.php
+msgid "Insufficient permissions"
+msgstr "Nedostatečná oprávnění"
+
+#: studiou-wc-product-cat-manage.php
+msgid "No file uploaded or upload error"
+msgstr "Žádný soubor nebyl nahrán nebo chyba nahrávání"
+
+#: studiou-wc-product-cat-manage.php
+msgid "No categories selected"
+msgstr "Nebyly vybrány žádné kategorie"
+
+#: studiou-wc-product-cat-manage.php
+msgid "Invalid request"
+msgstr "Neplatný požadavek"
+
+#. ==========================================
+#. Clear Media Categories (v1.5.0)
+#. ==========================================
+
+#: studiou-wc-product-cat-manage.php
+msgid "Are you sure you want to permanently delete ALL media files in the selected media categories? This action cannot be undone!"
+msgstr "Opravdu chcete trvale smazat VŠECHNY mediální soubory ve vybraných kategoriích médií? Tuto akci nelze vrátit zpět!"
+
+#: studiou-wc-product-cat-manage.php
+msgid "Clear media operation successful"
+msgstr "Operace vyčištění médií úspěšná"
+
+#: studiou-wc-product-cat-manage.php
+msgid "Clear media operation error"
+msgstr "Chyba operace vyčištění médií"
+
+#: studiou-wc-product-cat-manage.php
+msgid "No media files found in selected categories"
+msgstr "Ve vybraných kategoriích nebyly nalezeny žádné mediální soubory"
+
+#: views/manipulations.php
+msgid "Clear Media Categories"
+msgstr "Vyčistit kategorie médií"
+
+#: views/manipulations.php
+msgid "This operation allows you to permanently delete all media files from selected media categories. This action cannot be undone!"
+msgstr "Tato operace umožňuje trvale smazat všechny mediální soubory z vybraných kategorií médií. Tuto akci nelze vrátit zpět!"
+
+#: views/manipulations.php
+msgid "No media categories found. Please install a media category plugin (e.g., Media Library Categories) to use this feature."
+msgstr "Nebyly nalezeny žádné kategorie médií. Nainstalujte prosím plugin pro kategorie médií (např. Media Library Categories) pro použití této funkce."
+
+#: views/manipulations.php
+msgid "Select Media Categories"
+msgstr "Vyberte kategorie médií"
+
+#: views/manipulations.php
+msgid "Select the media categories from which all files will be permanently deleted."
+msgstr "Vyberte kategorie médií, ze kterých budou všechny soubory trvale smazány."
+
+#: views/manipulations.php
+msgid "WARNING: This operation will permanently delete all media files in the selected categories. The files will be removed from the server. This action cannot be undone!"
+msgstr "VAROVÁNÍ: Tato operace trvale smaže všechny mediální soubory ve vybraných kategoriích. Soubory budou odstraněny ze serveru. Tuto akci nelze vrátit zpět!"
+
+#: views/manipulations.php
+msgid "The clear media categories operation will permanently delete all media files from the selected media categories and remove them from the server. This action cannot be undone!"
+msgstr "Operace vyčištění kategorií médií trvale smaže všechny mediální soubory z vybraných kategorií médií a odstraní je ze serveru. Tuto akci nelze vrátit zpět!"
+
+#: includes/class-studiou-wc-product-cat-manage-manipulator.php
+msgid "files"
+msgstr "souborů"
+
+#: includes/class-studiou-wc-product-cat-manage-manipulator.php
+msgid "Found %d media files to delete"
+msgstr "Nalezeno %d mediálních souborů ke smazání"
+
+#: includes/class-studiou-wc-product-cat-manage-manipulator.php
+msgid "Error during clear media operation: %s"
+msgstr "Chyba během operace vyčištění médií: %s"
+
+#: includes/class-studiou-wc-product-cat-manage-manipulator.php
+msgid "Error during clear media batch operation: %s"
+msgstr "Chyba během dávkové operace vyčištění médií: %s"

+ 146 - 2
studiou-wc-product-cat-manage/languages/studiou-wc-product-cat-manage.po

@@ -2,9 +2,9 @@
 # This file is distributed under the same license as the QDR - Studiou WC Export/Import Product Categories package.
 msgid ""
 msgstr ""
-"Project-Id-Version: QDR - Studiou WC Export/Import Product Categories 1.2.1\n"
+"Project-Id-Version: QDR - Studiou WC Export/Import Product Categories 1.5.0\n"
 "Report-Msgid-Bugs-To: https://www.quadarax.com/plugins/studiou-wc-product-cat-manage\n"
-"POT-Creation-Date: 2025-05-15 12:00+0000\n"
+"POT-Creation-Date: 2026-04-01 12:00+0000\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
@@ -769,4 +769,148 @@ msgstr ""
 
 #: views/product-export.php:108
 msgid "The exported file can be modified and re-imported using the Product Import feature."
+msgstr ""
+
+#. ==========================================
+#. Delete Products in Category (v1.3.0)
+#. ==========================================
+
+#: studiou-wc-product-cat-manage.php
+msgid "Delete operation successful"
+msgstr ""
+
+#: studiou-wc-product-cat-manage.php
+msgid "Delete operation error"
+msgstr ""
+
+#: studiou-wc-product-cat-manage.php
+msgid "Are you sure you want to permanently delete ALL products in the selected categories? This action cannot be undone!"
+msgstr ""
+
+#: studiou-wc-product-cat-manage.php
+msgid "No products found in selected categories"
+msgstr ""
+
+#: views/manipulations.php
+msgid "Delete products in category"
+msgstr ""
+
+#: views/manipulations.php
+msgid "This operation allows you to permanently delete all products and their variants from selected categories. This action cannot be undone!"
+msgstr ""
+
+#: views/manipulations.php
+msgid "Select the categories from which all products will be permanently deleted."
+msgstr ""
+
+#: views/manipulations.php
+msgid "WARNING: This operation will permanently delete all products (including variants) in the selected categories. This action cannot be undone!"
+msgstr ""
+
+#: views/manipulations.php
+msgid "Delete"
+msgstr ""
+
+#: views/manipulations.php
+msgid "Deletion Progress"
+msgstr ""
+
+#: views/manipulations.php
+msgid "Deletion Results"
+msgstr ""
+
+#: views/manipulations.php
+msgid "The delete products operation will permanently delete all products and variants from the selected categories. This action cannot be undone!"
+msgstr ""
+
+#: includes/class-studiou-wc-product-cat-manage-manipulator.php
+msgid "Found %d products to delete"
+msgstr ""
+
+#: includes/class-studiou-wc-product-cat-manage-manipulator.php
+msgid "Error during delete operation: %s"
+msgstr ""
+
+#: includes/class-studiou-wc-product-cat-manage-manipulator.php
+msgid "Error during delete batch operation: %s"
+msgstr ""
+
+#: studiou-wc-product-cat-manage.php
+msgid "Insufficient permissions"
+msgstr ""
+
+#: studiou-wc-product-cat-manage.php
+msgid "No file uploaded or upload error"
+msgstr ""
+
+#: studiou-wc-product-cat-manage.php
+msgid "No categories selected"
+msgstr ""
+
+#: studiou-wc-product-cat-manage.php
+msgid "Invalid request"
+msgstr ""
+
+#. ==========================================
+#. Clear Media Categories (v1.5.0)
+#. ==========================================
+
+#: studiou-wc-product-cat-manage.php
+msgid "Are you sure you want to permanently delete ALL media files in the selected media categories? This action cannot be undone!"
+msgstr ""
+
+#: studiou-wc-product-cat-manage.php
+msgid "Clear media operation successful"
+msgstr ""
+
+#: studiou-wc-product-cat-manage.php
+msgid "Clear media operation error"
+msgstr ""
+
+#: studiou-wc-product-cat-manage.php
+msgid "No media files found in selected categories"
+msgstr ""
+
+#: views/manipulations.php
+msgid "Clear Media Categories"
+msgstr ""
+
+#: views/manipulations.php
+msgid "This operation allows you to permanently delete all media files from selected media categories. This action cannot be undone!"
+msgstr ""
+
+#: views/manipulations.php
+msgid "No media categories found. Please install a media category plugin (e.g., Media Library Categories) to use this feature."
+msgstr ""
+
+#: views/manipulations.php
+msgid "Select Media Categories"
+msgstr ""
+
+#: views/manipulations.php
+msgid "Select the media categories from which all files will be permanently deleted."
+msgstr ""
+
+#: views/manipulations.php
+msgid "WARNING: This operation will permanently delete all media files in the selected categories. The files will be removed from the server. This action cannot be undone!"
+msgstr ""
+
+#: views/manipulations.php
+msgid "The clear media categories operation will permanently delete all media files from the selected media categories and remove them from the server. This action cannot be undone!"
+msgstr ""
+
+#: includes/class-studiou-wc-product-cat-manage-manipulator.php
+msgid "files"
+msgstr ""
+
+#: includes/class-studiou-wc-product-cat-manage-manipulator.php
+msgid "Found %d media files to delete"
+msgstr ""
+
+#: includes/class-studiou-wc-product-cat-manage-manipulator.php
+msgid "Error during clear media operation: %s"
+msgstr ""
+
+#: includes/class-studiou-wc-product-cat-manage-manipulator.php
+msgid "Error during clear media batch operation: %s"
 msgstr ""

+ 42 - 1
studiou-wc-product-cat-manage/readme.md

@@ -1,6 +1,6 @@
 # QDR - Studiou WC Export/Import Product Categories
 
-**Version: 1.4**
+**Version: 1.5**
 
 A WordPress plugin that extends WooCommerce to provide batch export and import functionality for both product categories and products, along with category manipulation tools.
 
@@ -25,6 +25,7 @@ The plugin provides a complete solution for bulk product and category management
 - **Move products between categories** in bulk
 - **Batch description update** for multiple categories
 - **Delete products in category** - permanently delete all products and variants from selected categories
+- **Clear Media Categories** - permanently delete all media files from selected media categories (NEW in v1.5)
 
 ### Product Management (NEW in v1.4)
 - **Export products to CSV** - Export variable products and variations by category selection
@@ -217,6 +218,29 @@ The plugin uses CSV files with the following columns for products:
 - If a product belongs to multiple categories, it will still be deleted entirely from the system
 - The page will automatically reload after successful deletion to update category counts
 
+#### Clear Media Categories (NEW in v1.5)
+
+1. Go to Products > Category Manipulations
+2. Scroll to the "Clear Media Categories" section
+3. Select one or more media categories using the checkboxes
+   - Use "Check All" to select all media categories
+   - Use "Uncheck All" to deselect all media categories
+4. Click "Delete" button (you will be asked to confirm)
+5. Watch the progress bar as media files are being deleted in batches
+6. Review the deletion statistics showing:
+   - Total media files deleted
+   - Failed deletions (if any)
+   - Failed media IDs (if any)
+
+**Important Notes about Clear Media Categories:**
+- **THIS OPERATION PERMANENTLY DELETES ALL MEDIA FILES** from the selected media categories
+- **The files will be removed from the server. THIS ACTION CANNOT BE UNDONE!**
+- Requires a media category plugin (e.g., Media Library Categories) to be installed
+- Media files are deleted using `wp_delete_attachment()` for proper cleanup
+- Media files are processed in batches of 10 to prevent timeouts
+- A real-time progress bar shows the deletion progress
+- The page will automatically reload after successful deletion to update category counts
+
 ## Sample CSVs
 
 ### Sample Product Category CSV
@@ -255,6 +279,7 @@ After activation, the plugin adds the following menu items under **Products** in
   - Move products between categories
   - Batch description between categories
   - Delete products in category
+  - Clear Media Categories (NEW in v1.5)
 
 ### Product Management (NEW in v1.4)
 - **Product Import** - Batch import variable products and variations
@@ -275,6 +300,22 @@ For support, please visit [https://www.quadarax.com/plugins/studiou-wc-product-c
 
 ## Changelog
 
+### Version 1.5.0
+- **NEW: Clear Media Categories** - permanently delete all media files from selected media categories
+  - Checkbox list of media categories with file count per category
+  - Check All / Uncheck All functionality
+  - Confirmation dialog before deletion
+  - Real-time progress bar for deletion operations
+  - Batch processing for large-scale deletions (processes 10 media files at a time)
+  - Comprehensive deletion statistics and error reporting
+  - Enhanced warning messages for destructive operations
+  - Auto-detection of media category taxonomy (supports media_category, attachment_category, media-category)
+  - Graceful fallback message when no media category plugin is installed
+- 2 new AJAX handlers: `studiou_wcpcm_clear_media`, `studiou_wcpcm_clear_media_batch`
+- Updated Category Manipulations page with new Clear Media Categories section
+- Added Important Notes entry for the new feature
+- Version bumped to 1.5.0
+
 ### Version 1.4.0
 - **NEW: Product Import** - Batch import variable products and variations from CSV
   - **Batch processing** - Processes 5 products per batch to avoid PHP timeout (60 sec limit)

+ 6 - 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.4.0
+ * Version: 1.5.0
  * 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.4.0');
+if (!defined('STUDIOU_WCPCM_VERSION')) define('STUDIOU_WCPCM_VERSION', '1.5.0');
 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__));
@@ -273,6 +273,10 @@ class Studiou_WC_Product_Cat_Manage {
                     'confirmDelete' => __('Are you sure you want to permanently delete ALL products in the selected categories? This action cannot be undone!', 'studiou-wc-product-cat-manage'),
                     'selectAtLeastOneCategory' => __('Please select at least one category', 'studiou-wc-product-cat-manage'),
                     'noProductsFound' => __('No products found in selected categories', 'studiou-wc-product-cat-manage'),
+                    'confirmClearMedia' => __('Are you sure you want to permanently delete ALL media files in the selected media categories? This action cannot be undone!', 'studiou-wc-product-cat-manage'),
+                    'clearMediaSuccess' => __('Clear media operation successful', 'studiou-wc-product-cat-manage'),
+                    'clearMediaError' => __('Clear media operation error', 'studiou-wc-product-cat-manage'),
+                    'noMediaFound' => __('No media files found in selected categories', 'studiou-wc-product-cat-manage'),
                 )
             ));
             

+ 68 - 0
studiou-wc-product-cat-manage/views/manipulations.php

@@ -14,6 +14,7 @@ if (!defined('WPINC')) {
 // Get categories with counts for select boxes
 $manipulator = new Studiou_WC_Product_Cat_Manage_Manipulator(new Studiou_WC_Product_Cat_Manage_DB());
 $categories = $manipulator->get_categories_with_counts();
+$media_categories = $manipulator->get_media_categories_with_counts();
 ?>
 
 <div class="wrap studiou-wcpcm-wrap">
@@ -200,6 +201,72 @@ $categories = $manipulator->get_categories_with_counts();
         </div>
     </div>
 
+    <!-- Clear Media Categories Operation -->
+    <div class="studiou-wcpcm-card">
+        <h2><?php echo esc_html__('Clear Media Categories', 'studiou-wc-product-cat-manage'); ?></h2>
+
+        <p><?php echo esc_html__('This operation allows you to permanently delete all media files from selected media categories. This action cannot be undone!', 'studiou-wc-product-cat-manage'); ?></p>
+
+        <?php if (empty($media_categories)): ?>
+            <p><em><?php echo esc_html__('No media categories found. Please install a media category plugin (e.g., Media Library Categories) to use this feature.', 'studiou-wc-product-cat-manage'); ?></em></p>
+        <?php else: ?>
+            <form id="studiou-wcpcm-clear-media-form" method="post">
+                <table class="form-table">
+                    <tr>
+                        <th scope="row">
+                            <label for="clear_media_categories_list"><?php echo esc_html__('Select Media Categories', 'studiou-wc-product-cat-manage'); ?></label>
+                        </th>
+                        <td>
+                            <div class="studiou-wcpcm-categories-list-container">
+                                <div class="studiou-wcpcm-list-actions">
+                                    <button type="button" id="studiou-wcpcm-clear-media-check-all" class="button">
+                                        <?php echo esc_html__('Check All', 'studiou-wc-product-cat-manage'); ?>
+                                    </button>
+                                    <button type="button" id="studiou-wcpcm-clear-media-uncheck-all" class="button">
+                                        <?php echo esc_html__('Uncheck All', 'studiou-wc-product-cat-manage'); ?>
+                                    </button>
+                                </div>
+                                <div class="studiou-wcpcm-categories-list" id="clear_media_categories_list">
+                                    <?php foreach ($media_categories as $category): ?>
+                                        <label class="studiou-wcpcm-category-item">
+                                            <input type="checkbox" name="media_categories[]" value="<?php echo esc_attr($category['id']); ?>">
+                                            <span><?php echo esc_html($category['display_name']); ?></span>
+                                        </label>
+                                    <?php endforeach; ?>
+                                </div>
+                            </div>
+                            <p class="description"><?php echo esc_html__('Select the media categories from which all files will be permanently deleted.', 'studiou-wc-product-cat-manage'); ?></p>
+                        </td>
+                    </tr>
+                </table>
+
+                <div class="studiou-wcpcm-warning-message">
+                    <p><strong><?php echo esc_html__('WARNING: This operation will permanently delete all media files in the selected categories. The files will be removed from the server. This action cannot be undone!', 'studiou-wc-product-cat-manage'); ?></strong></p>
+                </div>
+
+                <div class="submit-buttons">
+                    <button type="submit" class="button button-primary button-danger" id="studiou-wcpcm-clear-media-button">
+                        <?php echo esc_html__('Delete', 'studiou-wc-product-cat-manage'); ?>
+                    </button>
+                    <span class="spinner"></span>
+                </div>
+            </form>
+
+            <div class="studiou-wcpcm-clear-media-progress" style="display: none;">
+                <h3><?php echo esc_html__('Deletion Progress', 'studiou-wc-product-cat-manage'); ?></h3>
+                <div class="studiou-wcpcm-progress-bar-container">
+                    <div class="studiou-wcpcm-progress-bar" id="studiou-wcpcm-clear-media-progress-bar"></div>
+                </div>
+                <div class="studiou-wcpcm-progress-text" id="studiou-wcpcm-clear-media-progress-text"></div>
+            </div>
+
+            <div class="studiou-wcpcm-clear-media-results" style="display: none;">
+                <h3><?php echo esc_html__('Deletion Results', 'studiou-wc-product-cat-manage'); ?></h3>
+                <div id="studiou-wcpcm-clear-media-message"></div>
+            </div>
+        <?php endif; ?>
+    </div>
+
     <!-- Important Notes -->
     <div class="studiou-wcpcm-card">
         <h2><?php echo esc_html__('Important Notes', 'studiou-wc-product-cat-manage'); ?></h2>
@@ -210,6 +277,7 @@ $categories = $manipulator->get_categories_with_counts();
             <li><?php echo esc_html__('The operation processes all products regardless of their status (published, draft, private).', 'studiou-wc-product-cat-manage'); ?></li>
             <li><?php echo esc_html__('The batch description operation will overwrite the existing descriptions for all selected categories.', 'studiou-wc-product-cat-manage'); ?></li>
             <li><strong><?php echo esc_html__('The delete products operation will permanently delete all products and variants from the selected categories. This action cannot be undone!', 'studiou-wc-product-cat-manage'); ?></strong></li>
+            <li><strong><?php echo esc_html__('The clear media categories operation will permanently delete all media files from the selected media categories and remove them from the server. This action cannot be undone!', 'studiou-wc-product-cat-manage'); ?></strong></li>
         </ul>
     </div>
 </div>