You've already forked wc-licensed-product
Fix version upload handling and add better error logging
- Fix VersionManager::createVersion() to handle null attachment_id properly - Add product type validation in AJAX version handler - Add database error logging for debugging - Improve meta box visibility logic for licensed products - Add known bug note to CLAUDE.md Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -105,23 +105,31 @@ class VersionManager
|
||||
$parsed = ProductVersion::parseVersion($version);
|
||||
|
||||
$tableName = Installer::getVersionsTable();
|
||||
$result = $wpdb->insert(
|
||||
$tableName,
|
||||
[
|
||||
'product_id' => $productId,
|
||||
'version' => $version,
|
||||
'major_version' => $parsed['major'],
|
||||
'minor_version' => $parsed['minor'],
|
||||
'patch_version' => $parsed['patch'],
|
||||
'release_notes' => $releaseNotes,
|
||||
'download_url' => $downloadUrl,
|
||||
'attachment_id' => $attachmentId,
|
||||
'is_active' => 1,
|
||||
],
|
||||
['%d', '%s', '%d', '%d', '%d', '%s', '%s', '%d', '%d']
|
||||
);
|
||||
|
||||
// Build data and formats arrays, handling null values properly
|
||||
$data = [
|
||||
'product_id' => $productId,
|
||||
'version' => $version,
|
||||
'major_version' => $parsed['major'],
|
||||
'minor_version' => $parsed['minor'],
|
||||
'patch_version' => $parsed['patch'],
|
||||
'release_notes' => $releaseNotes,
|
||||
'download_url' => $downloadUrl,
|
||||
'is_active' => 1,
|
||||
];
|
||||
$formats = ['%d', '%s', '%d', '%d', '%d', '%s', '%s', '%d'];
|
||||
|
||||
// Only include attachment_id if it's set
|
||||
if ($attachmentId !== null && $attachmentId > 0) {
|
||||
$data['attachment_id'] = $attachmentId;
|
||||
$formats[] = '%d';
|
||||
}
|
||||
|
||||
$result = $wpdb->insert($tableName, $data, $formats);
|
||||
|
||||
if ($result === false) {
|
||||
// Log error for debugging
|
||||
error_log('WC Licensed Product: Failed to create version - ' . $wpdb->last_error);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user