Implement versions 0.0.4-0.0.7 features

v0.0.4:
- Add WooCommerce settings tab for default license settings
- Per-product settings override global defaults

v0.0.5:
- Add bulk license operations (activate, deactivate, revoke, extend, delete)
- Add license renewal/extension and lifetime functionality
- Add quick action buttons per license row

v0.0.6:
- Add license dashboard with statistics and analytics
- Add license transfer functionality (admin)
- Add CSV export for licenses
- Add OpenAPI 3.1 specification
- Remove /deactivate API endpoint

v0.0.7:
- Move license dashboard to WooCommerce Reports section
- Add license search and filtering in admin
- Add customer-facing license transfer with AJAX modal
- Add email notifications for license expiration warnings
- Add bulk import licenses from CSV
- Update README with comprehensive documentation

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-21 20:32:35 +01:00
parent 78e43b9aea
commit 49a0699963
21 changed files with 4132 additions and 289 deletions

View File

@@ -0,0 +1,142 @@
<?php
/**
* Settings Controller
*
* @package Jeremias\WcLicensedProduct\Admin
*/
declare(strict_types=1);
namespace Jeremias\WcLicensedProduct\Admin;
/**
* Handles WooCommerce settings tab for license defaults
*/
final class SettingsController
{
/**
* Settings option name
*/
public const OPTION_NAME = 'wc_licensed_product_settings';
/**
* Constructor
*/
public function __construct()
{
$this->registerHooks();
}
/**
* Register WordPress hooks
*/
private function registerHooks(): void
{
add_filter('woocommerce_settings_tabs_array', [$this, 'addSettingsTab'], 50);
add_action('woocommerce_settings_tabs_licensed_product', [$this, 'renderSettingsTab']);
add_action('woocommerce_update_options_licensed_product', [$this, 'saveSettings']);
}
/**
* Add settings tab to WooCommerce settings
*/
public function addSettingsTab(array $tabs): array
{
$tabs['licensed_product'] = __('Licensed Products', 'wc-licensed-product');
return $tabs;
}
/**
* Get settings fields
*/
public function getSettingsFields(): array
{
return [
'section_title' => [
'name' => __('Default License Settings', 'wc-licensed-product'),
'type' => 'title',
'desc' => __('These settings serve as defaults for new licensed products. Individual product settings override these defaults.', 'wc-licensed-product'),
'id' => 'wc_licensed_product_section_defaults',
],
'default_max_activations' => [
'name' => __('Default Max Activations', 'wc-licensed-product'),
'type' => 'number',
'desc' => __('Default maximum number of domain activations per license.', 'wc-licensed-product'),
'id' => 'wc_licensed_product_default_max_activations',
'default' => '1',
'custom_attributes' => [
'min' => '1',
'step' => '1',
],
],
'default_validity_days' => [
'name' => __('Default License Validity (Days)', 'wc-licensed-product'),
'type' => 'number',
'desc' => __('Default number of days a license is valid. Leave empty or set to 0 for lifetime licenses.', 'wc-licensed-product'),
'id' => 'wc_licensed_product_default_validity_days',
'default' => '',
'placeholder' => __('Lifetime', 'wc-licensed-product'),
'custom_attributes' => [
'min' => '0',
'step' => '1',
],
],
'default_bind_to_version' => [
'name' => __('Default Bind to Major Version', 'wc-licensed-product'),
'type' => 'checkbox',
'desc' => __('If enabled, licenses are bound to the major version at purchase time by default.', 'wc-licensed-product'),
'id' => 'wc_licensed_product_default_bind_to_version',
'default' => 'no',
],
'section_end' => [
'type' => 'sectionend',
'id' => 'wc_licensed_product_section_defaults_end',
],
];
}
/**
* Render settings tab content
*/
public function renderSettingsTab(): void
{
woocommerce_admin_fields($this->getSettingsFields());
}
/**
* Save settings
*/
public function saveSettings(): void
{
woocommerce_update_options($this->getSettingsFields());
}
/**
* Get default max activations
*/
public static function getDefaultMaxActivations(): int
{
$value = get_option('wc_licensed_product_default_max_activations', 1);
return max(1, (int) $value);
}
/**
* Get default validity days
*/
public static function getDefaultValidityDays(): ?int
{
$value = get_option('wc_licensed_product_default_validity_days', '');
if ($value === '' || $value === '0') {
return null;
}
return (int) $value;
}
/**
* Get default bind to version setting
*/
public static function getDefaultBindToVersion(): bool
{
return get_option('wc_licensed_product_default_bind_to_version', 'no') === 'yes';
}
}