You've already forked wc-licensed-product
Implement version 0.0.3 features
- Add file attachment support for product versions (Media Library) - Add version auto-detection from uploaded filenames - Implement secure customer downloads with hash verification - Add license key copy-to-clipboard functionality - Redesign customer licenses page with card-based UI - Fix product versions meta box visibility for non-licensed types - Add DownloadController for secure file delivery - Update CLAUDE.md roadmap and session history Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -8,6 +8,8 @@
|
||||
'use strict';
|
||||
|
||||
var WCLicensedProductVersions = {
|
||||
mediaFrame: null,
|
||||
|
||||
init: function() {
|
||||
this.bindEvents();
|
||||
},
|
||||
@@ -16,6 +18,113 @@
|
||||
$('#add-version-btn').on('click', this.addVersion);
|
||||
$(document).on('click', '.delete-version-btn', this.deleteVersion);
|
||||
$(document).on('click', '.toggle-version-btn', this.toggleVersion);
|
||||
|
||||
// Media uploader events
|
||||
$('#upload-version-file-btn').on('click', this.openMediaUploader.bind(this));
|
||||
$('#remove-version-file-btn').on('click', this.removeSelectedFile);
|
||||
|
||||
// Listen for product type changes
|
||||
$('#product-type').on('change', this.onProductTypeChange);
|
||||
|
||||
// Initial check for product type (handles page load for new products)
|
||||
this.onProductTypeChange();
|
||||
},
|
||||
|
||||
onProductTypeChange: function() {
|
||||
var productType = $('#product-type').val();
|
||||
var $metaBox = $('#wc_licensed_product_versions');
|
||||
|
||||
if (productType === 'licensed') {
|
||||
$metaBox.show();
|
||||
} else {
|
||||
$metaBox.hide();
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Open WordPress media uploader
|
||||
*/
|
||||
openMediaUploader: function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
var self = this;
|
||||
|
||||
// If frame already exists, open it
|
||||
if (this.mediaFrame) {
|
||||
this.mediaFrame.open();
|
||||
return;
|
||||
}
|
||||
|
||||
// Create media frame
|
||||
this.mediaFrame = wp.media({
|
||||
title: wcLicensedProductVersions.strings.selectFile,
|
||||
button: {
|
||||
text: wcLicensedProductVersions.strings.useThisFile
|
||||
},
|
||||
multiple: false,
|
||||
library: {
|
||||
type: ['application/zip', 'application/x-zip-compressed', 'application/octet-stream']
|
||||
}
|
||||
});
|
||||
|
||||
// When file is selected
|
||||
this.mediaFrame.on('select', function() {
|
||||
var attachment = self.mediaFrame.state().get('selection').first().toJSON();
|
||||
|
||||
// Set attachment ID
|
||||
$('#new_attachment_id').val(attachment.id);
|
||||
|
||||
// Show filename
|
||||
$('#selected_file_name').text(attachment.filename);
|
||||
$('#remove-version-file-btn').show();
|
||||
|
||||
// Try to extract version from filename
|
||||
var extractedVersion = self.extractVersionFromFilename(attachment.filename);
|
||||
if (extractedVersion && !$('#new_version').val().trim()) {
|
||||
$('#new_version').val(extractedVersion);
|
||||
}
|
||||
|
||||
// Clear external URL when file is selected
|
||||
$('#new_download_url').val('');
|
||||
});
|
||||
|
||||
this.mediaFrame.open();
|
||||
},
|
||||
|
||||
/**
|
||||
* Remove selected file
|
||||
*/
|
||||
removeSelectedFile: function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
$('#new_attachment_id').val('');
|
||||
$('#selected_file_name').text('');
|
||||
$('#remove-version-file-btn').hide();
|
||||
},
|
||||
|
||||
/**
|
||||
* Extract version from filename
|
||||
* Supports patterns like: plugin-v1.2.3.zip, plugin-1.2.3.zip, v1.2.3.zip
|
||||
*/
|
||||
extractVersionFromFilename: function(filename) {
|
||||
// Remove extension
|
||||
var basename = filename.replace(/\.[^/.]+$/, '');
|
||||
|
||||
// Try various patterns
|
||||
var patterns = [
|
||||
/[_-]v?(\d+\.\d+\.\d+)$/i, // ends with -v1.2.3 or -1.2.3
|
||||
/[_-]v?(\d+\.\d+\.\d+)[_-]/i, // contains -v1.2.3- or -1.2.3-
|
||||
/^v?(\d+\.\d+\.\d+)$/i // just version number
|
||||
];
|
||||
|
||||
for (var i = 0; i < patterns.length; i++) {
|
||||
var match = basename.match(patterns[i]);
|
||||
if (match) {
|
||||
return match[1];
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
},
|
||||
|
||||
addVersion: function(e) {
|
||||
@@ -27,6 +136,7 @@
|
||||
var version = $('#new_version').val().trim();
|
||||
var downloadUrl = $('#new_download_url').val().trim();
|
||||
var releaseNotes = $('#new_release_notes').val().trim();
|
||||
var attachmentId = $('#new_attachment_id').val();
|
||||
|
||||
// Validate version
|
||||
if (!version) {
|
||||
@@ -51,7 +161,8 @@
|
||||
product_id: productId,
|
||||
version: version,
|
||||
download_url: downloadUrl,
|
||||
release_notes: releaseNotes
|
||||
release_notes: releaseNotes,
|
||||
attachment_id: attachmentId
|
||||
},
|
||||
success: function(response) {
|
||||
if (response.success) {
|
||||
@@ -65,6 +176,9 @@
|
||||
$('#new_version').val('');
|
||||
$('#new_download_url').val('');
|
||||
$('#new_release_notes').val('');
|
||||
$('#new_attachment_id').val('');
|
||||
$('#selected_file_name').text('');
|
||||
$('#remove-version-file-btn').hide();
|
||||
} else {
|
||||
alert(response.data.message || wcLicensedProductVersions.strings.error);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user