Major improvements: Fix download limits, enhance license display, fix software filenames

🔧 Bug Fixes:
- Fixed download limits defaulting to 5 instead of 0 for unlimited downloads
- Fixed software license filename sanitization (spaces→dashes, dots→underscores, proper .zip extension)
- Software downloads now show as "Test-Plugin-v2-2-0.zip" instead of "Test Plugin v2.2.0"

 UI/UX Enhancements:
- Redesigned license key display to span full table width with FontAwesome copy icons
- Added responsive CSS styling for license key rows
- Integrated FontAwesome CDN for modern copy icons

🏗️ Architecture Improvements:
- Added comprehensive filename sanitization in both download handler and API paths
- Enhanced software license product handling for local package files
- Improved error handling and logging throughout download processes

📦 Infrastructure:
- Added Gitea workflows for automated releases on push to main
- Created comprehensive .gitignore excluding test files and browser automation
- Updated documentation with all recent improvements and technical insights

🔍 Technical Details:
- Software license products served from wp-content/uploads/wpdd-packages/
- Download flow: token → process_download_by_token() → process_download() → deliver_file()
- Dual path coverage for both API downloads and regular file delivery
- Version placeholder system for automated deployment

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-09-09 19:16:57 -07:00
parent ce48f1615f
commit a160fe3964
28 changed files with 3709 additions and 156 deletions

View File

@@ -86,14 +86,72 @@ class WPDD_Creator {
}
public static function get_creator_balance($user_id) {
return floatval(get_user_meta($user_id, 'wpdd_creator_balance', true));
global $wpdb;
// Get balance from user meta (for backward compatibility and manual adjustments)
$meta_balance = floatval(get_user_meta($user_id, 'wpdd_creator_balance', true));
// If we have the creator_earnings table, calculate from there
$table_exists = $wpdb->get_var("SHOW TABLES LIKE '{$wpdb->prefix}wpdd_creator_earnings'") == $wpdb->prefix . 'wpdd_creator_earnings';
if ($table_exists) {
// Check if payout_status column exists
$columns = $wpdb->get_results("SHOW COLUMNS FROM {$wpdb->prefix}wpdd_creator_earnings");
$has_payout_status = false;
foreach ($columns as $column) {
if ($column->Field == 'payout_status') {
$has_payout_status = true;
break;
}
}
if ($has_payout_status) {
// Calculate available earnings (not pending, not paid)
$available_earnings = $wpdb->get_var($wpdb->prepare(
"SELECT SUM(creator_earning)
FROM {$wpdb->prefix}wpdd_creator_earnings
WHERE creator_id = %d
AND payout_status = 'available'",
$user_id
));
// Calculate balance adjustments
$adjustments_table_exists = $wpdb->get_var("SHOW TABLES LIKE '{$wpdb->prefix}wpdd_balance_adjustments'") == $wpdb->prefix . 'wpdd_balance_adjustments';
$total_adjustments = 0;
if ($adjustments_table_exists) {
$total_adjustments = $wpdb->get_var($wpdb->prepare(
"SELECT SUM(CASE
WHEN adjustment_type = 'add' THEN amount
WHEN adjustment_type = 'subtract' THEN -amount
ELSE 0
END)
FROM {$wpdb->prefix}wpdd_balance_adjustments
WHERE creator_id = %d",
$user_id
));
}
$calculated_balance = floatval($available_earnings) + floatval($total_adjustments);
// Update the meta if different
if (abs($calculated_balance - $meta_balance) > 0.01) {
update_user_meta($user_id, 'wpdd_creator_balance', $calculated_balance);
}
return $calculated_balance;
}
}
// Fall back to meta balance
return $meta_balance;
}
public static function get_creator_total_earnings($user_id) {
global $wpdb;
$total = $wpdb->get_var($wpdb->prepare(
"SELECT SUM(o.total)
"SELECT SUM(o.amount)
FROM {$wpdb->prefix}wpdd_orders o
INNER JOIN {$wpdb->posts} p ON o.product_id = p.ID
WHERE p.post_author = %d
@@ -130,12 +188,20 @@ class WPDD_Creator {
$creator_id = $product->post_author;
$commission_rate = floatval(get_option('wpdd_commission_rate', 0));
$creator_share = $order->total * (1 - ($commission_rate / 100));
$creator_share = $order->amount * (1 - ($commission_rate / 100));
// Update creator balance
$current_balance = self::get_creator_balance($creator_id);
update_user_meta($creator_id, 'wpdd_creator_balance', $current_balance + $creator_share);
// Calculate when earnings will be available (holding period)
$holding_days = intval(get_option('wpdd_earnings_holding_days', 15));
$available_at = ($holding_days > 0) ?
date('Y-m-d H:i:s', strtotime('+' . $holding_days . ' days')) :
current_time('mysql');
$initial_status = ($holding_days > 0) ? 'pending' : 'available';
// Log the earning
$wpdb->insert(
$wpdb->prefix . 'wpdd_creator_earnings',
@@ -143,12 +209,14 @@ class WPDD_Creator {
'creator_id' => $creator_id,
'order_id' => $order_id,
'product_id' => $order->product_id,
'sale_amount' => $order->total,
'sale_amount' => $order->amount,
'commission_rate' => $commission_rate,
'creator_earning' => $creator_share,
'payout_status' => $initial_status,
'available_at' => $available_at,
'created_at' => current_time('mysql')
),
array('%d', '%d', '%d', '%f', '%f', '%f', '%s')
array('%d', '%d', '%d', '%f', '%f', '%f', '%s', '%s', '%s')
);
}