on() {
    if (isset($_POST['subaction']) && $_POST['subaction'] === 'suspend_vendor') {
        error_log('=== SUSPENSION ACTION TRIGGERED ===');
        error_log('Vendor ID: ' . ($_POST['id'] ?? 'not set'));
        error_log('POST data: ' . print_r($_POST, true));
    }
}, 1);



/**
 * Admin action to migrate existing suspended vendors to blacklist
 * Access: yourdomain.com/wp-admin/admin.php?action=migrate_suspended_to_blacklist
 */
add_action('admin_action_migrate_suspended_to_blacklist', 'addiscart_migrate_suspended_vendors_to_blacklist');

function addiscart_migrate_suspended_vendors_to_blacklist() {
    if (!current_user_can('manage_options')) {
        wp_die('Unauthorized');
    }
    
    global $wpdb;
    
    $suspended_vendors = $wpdb->get_results("
        SELECT id, status, suspended_at, suspended_by 
        FROM addis_vendors 
        WHERE status IN ('suspended', 'rejected')
    ");
    
    $migrated = 0;
    $failed = 0;
    
    foreach ($suspended_vendors as $vendor) {
        if (function_exists('addiscart_store_vendor_in_blacklist_complete')) {
            $result = addiscart_store_vendor_in_blacklist_complete(
                $vendor->id, 
                'Migrated from existing ' . $vendor->status . ' status', 
                $vendor->status === 'rejected' ? 'banned' : 'suspended',
                'Auto-migrated from existing vendor status'
            );
            
            if ($result['success']) {
                $migrated++;
            } else {
                $failed++;
                error_log('Failed to migrate vendor ' . $vendor->id . ': ' . $result['message']);
            }
        }
    }
    
    echo '<h1>Vendor Blacklist Migration Complete</h1>';
    echo '<p><strong>Migrated:</strong> ' . $migrated . ' vendors</p>';
    echo '<p><strong>Failed:</strong> ' . $failed . ' vendors</p>';
    echo '<p><a href="' . admin_url() . '">Back to Admin</a></p>';
    exit;
}
?><?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="https://www.addiscart.com/wp-sitemap.xsl" ?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"><url><loc>https://www.addiscart.com/author/addiscart/</loc></url></urlset>
