Add license test action to admin overview

Added a "Test" action button in the license overview that validates
licenses against the /validate REST API endpoint. Results are shown
in a modal with validation status, error codes, and license details.

- Added Test link in row actions for each license
- Created AJAX handler handleAjaxTestLicense() in AdminController
- Added test result modal with loading state and result display
- Shows valid/invalid status with detailed error information

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-23 11:37:06 +01:00
parent 1bc643408e
commit 8b87c954eb
2 changed files with 150 additions and 0 deletions

View File

@@ -61,6 +61,9 @@ final class AdminController
add_action('wp_ajax_wclp_update_license_expiry', [$this, 'handleAjaxExpiryUpdate']);
add_action('wp_ajax_wclp_update_license_domain', [$this, 'handleAjaxDomainUpdate']);
add_action('wp_ajax_wclp_revoke_license', [$this, 'handleAjaxRevoke']);
// AJAX handler for license testing
add_action('wp_ajax_wclp_test_license', [$this, 'handleAjaxTestLicense']);
}
/**
@@ -355,6 +358,30 @@ final class AdminController
}
}
/**
* Handle AJAX license test - validates license against the API
*/
public function handleAjaxTestLicense(): void
{
check_ajax_referer('wclp_inline_edit', 'nonce');
if (!current_user_can('manage_woocommerce')) {
wp_send_json_error(['message' => __('Permission denied.', 'wc-licensed-product')], 403);
}
$licenseKey = isset($_POST['license_key']) ? sanitize_text_field(wp_unslash($_POST['license_key'])) : '';
$domain = isset($_POST['domain']) ? sanitize_text_field(wp_unslash($_POST['domain'])) : '';
if (empty($licenseKey) || empty($domain)) {
wp_send_json_error(['message' => __('License key and domain are required.', 'wc-licensed-product')]);
}
// Validate the license using LicenseManager
$result = $this->licenseManager->validateLicense($licenseKey, $domain);
wp_send_json_success($result);
}
/**
* Handle admin actions (update, delete licenses)
*/