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:
@@ -10,6 +10,7 @@ declare(strict_types=1);
|
||||
namespace Jeremias\WcLicensedProduct\Frontend;
|
||||
|
||||
use Jeremias\WcLicensedProduct\License\LicenseManager;
|
||||
use Jeremias\WcLicensedProduct\Product\VersionManager;
|
||||
use Twig\Environment;
|
||||
|
||||
/**
|
||||
@@ -19,11 +20,19 @@ final class AccountController
|
||||
{
|
||||
private Environment $twig;
|
||||
private LicenseManager $licenseManager;
|
||||
private VersionManager $versionManager;
|
||||
private DownloadController $downloadController;
|
||||
|
||||
public function __construct(Environment $twig, LicenseManager $licenseManager)
|
||||
{
|
||||
public function __construct(
|
||||
Environment $twig,
|
||||
LicenseManager $licenseManager,
|
||||
VersionManager $versionManager,
|
||||
DownloadController $downloadController
|
||||
) {
|
||||
$this->twig = $twig;
|
||||
$this->licenseManager = $licenseManager;
|
||||
$this->versionManager = $versionManager;
|
||||
$this->downloadController = $downloadController;
|
||||
$this->registerHooks();
|
||||
}
|
||||
|
||||
@@ -41,8 +50,8 @@ final class AccountController
|
||||
// Add licenses endpoint content
|
||||
add_action('woocommerce_account_licenses_endpoint', [$this, 'displayLicensesContent']);
|
||||
|
||||
// Enqueue frontend styles
|
||||
add_action('wp_enqueue_scripts', [$this, 'enqueueStyles']);
|
||||
// Enqueue frontend styles and scripts
|
||||
add_action('wp_enqueue_scripts', [$this, 'enqueueAssets']);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -83,18 +92,40 @@ final class AccountController
|
||||
|
||||
$licenses = $this->licenseManager->getLicensesByCustomer($customerId);
|
||||
|
||||
// Enrich licenses with product data
|
||||
// Enrich licenses with product data and downloads
|
||||
$enrichedLicenses = [];
|
||||
foreach ($licenses as $license) {
|
||||
$product = wc_get_product($license->getProductId());
|
||||
$order = wc_get_order($license->getOrderId());
|
||||
|
||||
// Get available downloads for this license
|
||||
$downloads = [];
|
||||
if ($license->getStatus() === 'active') {
|
||||
$versions = $this->versionManager->getVersionsByProduct($license->getProductId());
|
||||
foreach ($versions as $version) {
|
||||
if ($version->isActive() && ($version->getAttachmentId() || $version->getDownloadUrl())) {
|
||||
$downloads[] = [
|
||||
'version' => $version->getVersion(),
|
||||
'version_id' => $version->getId(),
|
||||
'filename' => $version->getDownloadFilename(),
|
||||
'download_url' => $this->downloadController->generateDownloadUrl(
|
||||
$license->getId(),
|
||||
$version->getId()
|
||||
),
|
||||
'release_notes' => $version->getReleaseNotes(),
|
||||
'released_at' => $version->getReleasedAt()->format(get_option('date_format')),
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$enrichedLicenses[] = [
|
||||
'license' => $license,
|
||||
'product_name' => $product ? $product->get_name() : __('Unknown Product', 'wc-licensed-product'),
|
||||
'product_url' => $product ? $product->get_permalink() : '',
|
||||
'order_number' => $order ? $order->get_order_number() : '',
|
||||
'order_url' => $order ? $order->get_view_order_url() : '',
|
||||
'downloads' => $downloads,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -120,23 +151,11 @@ final class AccountController
|
||||
}
|
||||
|
||||
?>
|
||||
<table class="woocommerce-licenses-table shop_table shop_table_responsive">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><?php esc_html_e('License Key', 'wc-licensed-product'); ?></th>
|
||||
<th><?php esc_html_e('Product', 'wc-licensed-product'); ?></th>
|
||||
<th><?php esc_html_e('Domain', 'wc-licensed-product'); ?></th>
|
||||
<th><?php esc_html_e('Status', 'wc-licensed-product'); ?></th>
|
||||
<th><?php esc_html_e('Expires', 'wc-licensed-product'); ?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($enrichedLicenses as $item): ?>
|
||||
<tr>
|
||||
<td data-title="<?php esc_attr_e('License Key', 'wc-licensed-product'); ?>">
|
||||
<code><?php echo esc_html($item['license']->getLicenseKey()); ?></code>
|
||||
</td>
|
||||
<td data-title="<?php esc_attr_e('Product', 'wc-licensed-product'); ?>">
|
||||
<div class="woocommerce-licenses">
|
||||
<?php foreach ($enrichedLicenses as $item): ?>
|
||||
<div class="license-card">
|
||||
<div class="license-header">
|
||||
<h3>
|
||||
<?php if ($item['product_url']): ?>
|
||||
<a href="<?php echo esc_url($item['product_url']); ?>">
|
||||
<?php echo esc_html($item['product_name']); ?>
|
||||
@@ -144,34 +163,63 @@ final class AccountController
|
||||
<?php else: ?>
|
||||
<?php echo esc_html($item['product_name']); ?>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
<td data-title="<?php esc_attr_e('Domain', 'wc-licensed-product'); ?>">
|
||||
<?php echo esc_html($item['license']->getDomain()); ?>
|
||||
</td>
|
||||
<td data-title="<?php esc_attr_e('Status', 'wc-licensed-product'); ?>">
|
||||
<span class="license-status license-status-<?php echo esc_attr($item['license']->getStatus()); ?>">
|
||||
<?php echo esc_html(ucfirst($item['license']->getStatus())); ?>
|
||||
</h3>
|
||||
<span class="license-status license-status-<?php echo esc_attr($item['license']->getStatus()); ?>">
|
||||
<?php echo esc_html(ucfirst($item['license']->getStatus())); ?>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="license-details">
|
||||
<div class="license-key-row">
|
||||
<label><?php esc_html_e('License Key:', 'wc-licensed-product'); ?></label>
|
||||
<code class="license-key" data-license-key="<?php echo esc_attr($item['license']->getLicenseKey()); ?>">
|
||||
<?php echo esc_html($item['license']->getLicenseKey()); ?>
|
||||
</code>
|
||||
<button type="button" class="copy-license-btn" data-license-key="<?php echo esc_attr($item['license']->getLicenseKey()); ?>" title="<?php esc_attr_e('Copy to clipboard', 'wc-licensed-product'); ?>">
|
||||
<span class="dashicons dashicons-clipboard"></span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="license-info-row">
|
||||
<span><strong><?php esc_html_e('Domain:', 'wc-licensed-product'); ?></strong> <?php echo esc_html($item['license']->getDomain()); ?></span>
|
||||
<span><strong><?php esc_html_e('Expires:', 'wc-licensed-product'); ?></strong>
|
||||
<?php
|
||||
$expiresAt = $item['license']->getExpiresAt();
|
||||
echo $expiresAt
|
||||
? esc_html($expiresAt->format(get_option('date_format')))
|
||||
: esc_html__('Never', 'wc-licensed-product');
|
||||
?>
|
||||
</span>
|
||||
</td>
|
||||
<td data-title="<?php esc_attr_e('Expires', 'wc-licensed-product'); ?>">
|
||||
<?php
|
||||
$expiresAt = $item['license']->getExpiresAt();
|
||||
echo $expiresAt
|
||||
? esc_html($expiresAt->format(get_option('date_format')))
|
||||
: esc_html__('Never', 'wc-licensed-product');
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php if (!empty($item['downloads'])): ?>
|
||||
<div class="license-downloads">
|
||||
<h4><?php esc_html_e('Available Downloads', 'wc-licensed-product'); ?></h4>
|
||||
<ul class="download-list">
|
||||
<?php foreach ($item['downloads'] as $download): ?>
|
||||
<li>
|
||||
<a href="<?php echo esc_url($download['download_url']); ?>" class="download-link">
|
||||
<span class="dashicons dashicons-download"></span>
|
||||
<?php echo esc_html($download['filename'] ?: sprintf(__('Version %s', 'wc-licensed-product'), $download['version'])); ?>
|
||||
</a>
|
||||
<span class="download-version">v<?php echo esc_html($download['version']); ?></span>
|
||||
<span class="download-date"><?php echo esc_html($download['released_at']); ?></span>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueue frontend styles
|
||||
* Enqueue frontend styles and scripts
|
||||
*/
|
||||
public function enqueueStyles(): void
|
||||
public function enqueueAssets(): void
|
||||
{
|
||||
if (!is_account_page()) {
|
||||
return;
|
||||
@@ -183,5 +231,20 @@ final class AccountController
|
||||
[],
|
||||
WC_LICENSED_PRODUCT_VERSION
|
||||
);
|
||||
|
||||
wp_enqueue_script(
|
||||
'wc-licensed-product-frontend',
|
||||
WC_LICENSED_PRODUCT_PLUGIN_URL . 'assets/js/frontend.js',
|
||||
['jquery'],
|
||||
WC_LICENSED_PRODUCT_VERSION,
|
||||
true
|
||||
);
|
||||
|
||||
wp_localize_script('wc-licensed-product-frontend', 'wcLicensedProduct', [
|
||||
'strings' => [
|
||||
'copied' => __('Copied!', 'wc-licensed-product'),
|
||||
'copyFailed' => __('Copy failed', 'wc-licensed-product'),
|
||||
],
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user