You've already forked wc-licensed-product
Add Test and Transfer actions to PHP fallback template
The PHP fallback template (used when Twig fails) was missing the Test license action and Transfer modal that were present in the Twig template. - Added Test license link to row actions in PHP fallback - Added Transfer link to row actions in PHP fallback - Added Test License modal with AJAX validation - Added Transfer License modal - Added JavaScript handlers for both modals Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1374,7 +1374,20 @@ final class AdminController
|
||||
</td>
|
||||
<td class="license-actions">
|
||||
<div class="row-actions">
|
||||
<span class="test">
|
||||
<a href="#" class="wclp-test-license-link"
|
||||
data-license-id="<?php echo esc_attr($item['license']->getId()); ?>"
|
||||
data-license-key="<?php echo esc_attr($item['license']->getLicenseKey()); ?>"
|
||||
data-domain="<?php echo esc_attr($item['license']->getDomain()); ?>"
|
||||
title="<?php esc_attr_e('Test license against API', 'wc-licensed-product'); ?>"><?php esc_html_e('Test', 'wc-licensed-product'); ?></a> |
|
||||
</span>
|
||||
<?php if ($item['license']->getStatus() !== License::STATUS_REVOKED): ?>
|
||||
<span class="transfer">
|
||||
<a href="#" class="wclp-transfer-link"
|
||||
data-license-id="<?php echo esc_attr($item['license']->getId()); ?>"
|
||||
data-current-domain="<?php echo esc_attr($item['license']->getDomain()); ?>"
|
||||
title="<?php esc_attr_e('Transfer to new domain', 'wc-licensed-product'); ?>"><?php esc_html_e('Transfer', 'wc-licensed-product'); ?></a> |
|
||||
</span>
|
||||
<span class="extend">
|
||||
<a href="<?php echo esc_url(wp_nonce_url(
|
||||
admin_url('admin.php?page=wc-licenses&action=extend&license_id=' . $item['license']->getId() . '&days=30'),
|
||||
@@ -1456,8 +1469,69 @@ final class AdminController
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<!-- Test License Modal -->
|
||||
<div id="wclp-test-modal" class="wclp-modal" style="display:none;">
|
||||
<div class="wclp-modal-content">
|
||||
<span class="wclp-modal-close">×</span>
|
||||
<h2><?php esc_html_e('License Validation Test', 'wc-licensed-product'); ?></h2>
|
||||
<div class="wclp-test-info">
|
||||
<table class="form-table">
|
||||
<tr>
|
||||
<th scope="row"><?php esc_html_e('License Key', 'wc-licensed-product'); ?></th>
|
||||
<td><code id="test-license-key"></code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row"><?php esc_html_e('Domain', 'wc-licensed-product'); ?></th>
|
||||
<td><code id="test-domain"></code></td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<div id="wclp-test-loading" style="display:none; text-align:center; padding:20px;">
|
||||
<span class="spinner is-active" style="float:none;"></span>
|
||||
<p><?php esc_html_e('Testing license...', 'wc-licensed-product'); ?></p>
|
||||
</div>
|
||||
<div id="wclp-test-result" style="display:none;">
|
||||
<div id="wclp-test-result-content"></div>
|
||||
</div>
|
||||
<p class="submit">
|
||||
<button type="button" class="button wclp-modal-cancel"><?php esc_html_e('Close', 'wc-licensed-product'); ?></button>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Transfer Modal -->
|
||||
<div id="wclp-transfer-modal" class="wclp-modal" style="display:none;">
|
||||
<div class="wclp-modal-content">
|
||||
<span class="wclp-modal-close">×</span>
|
||||
<h2><?php esc_html_e('Transfer License to New Domain', 'wc-licensed-product'); ?></h2>
|
||||
<form method="post" action="<?php echo esc_url(admin_url('admin.php?page=wc-licenses')); ?>">
|
||||
<input type="hidden" name="action" value="transfer_license">
|
||||
<?php wp_nonce_field('transfer_license', '_wpnonce'); ?>
|
||||
<input type="hidden" name="license_id" id="transfer-license-id" value="">
|
||||
<table class="form-table">
|
||||
<tr>
|
||||
<th scope="row"><label><?php esc_html_e('Current Domain', 'wc-licensed-product'); ?></label></th>
|
||||
<td><code id="transfer-current-domain"></code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row"><label for="new_domain"><?php esc_html_e('New Domain', 'wc-licensed-product'); ?></label></th>
|
||||
<td>
|
||||
<input type="text" name="new_domain" id="transfer-new-domain" class="regular-text" placeholder="example.com" required>
|
||||
<p class="description"><?php esc_html_e('Enter the new domain without http:// or www.', 'wc-licensed-product'); ?></p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<p class="submit">
|
||||
<button type="submit" class="button button-primary"><?php esc_html_e('Transfer License', 'wc-licensed-product'); ?></button>
|
||||
<button type="button" class="button wclp-modal-cancel"><?php esc_html_e('Cancel', 'wc-licensed-product'); ?></button>
|
||||
</p>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
(function($) {
|
||||
// Checkbox select all
|
||||
$('#cb-select-all-1, #cb-select-all-2').on('change', function() {
|
||||
$('input[name="license_ids[]"]').prop('checked', this.checked);
|
||||
$('#cb-select-all-1, #cb-select-all-2').prop('checked', this.checked);
|
||||
@@ -1472,6 +1546,102 @@ final class AdminController
|
||||
$('#bulk-action-selector').val(bottomAction);
|
||||
}
|
||||
});
|
||||
|
||||
// Transfer modal
|
||||
var $transferModal = $('#wclp-transfer-modal');
|
||||
$('.wclp-transfer-link').on('click', function(e) {
|
||||
e.preventDefault();
|
||||
var licenseId = $(this).data('license-id');
|
||||
var currentDomain = $(this).data('current-domain');
|
||||
$('#transfer-license-id').val(licenseId);
|
||||
$('#transfer-current-domain').text(currentDomain);
|
||||
$('#transfer-new-domain').val('');
|
||||
$transferModal.show();
|
||||
});
|
||||
|
||||
// Test License modal
|
||||
var $testModal = $('#wclp-test-modal');
|
||||
var $testLoading = $('#wclp-test-loading');
|
||||
var $testResult = $('#wclp-test-result');
|
||||
var $testResultContent = $('#wclp-test-result-content');
|
||||
|
||||
$('.wclp-test-license-link').on('click', function(e) {
|
||||
e.preventDefault();
|
||||
var licenseKey = $(this).data('license-key');
|
||||
var domain = $(this).data('domain');
|
||||
|
||||
$('#test-license-key').text(licenseKey);
|
||||
$('#test-domain').text(domain);
|
||||
$testLoading.show();
|
||||
$testResult.hide();
|
||||
$testModal.show();
|
||||
|
||||
$.ajax({
|
||||
url: wclpAdmin.ajaxUrl,
|
||||
type: 'POST',
|
||||
data: {
|
||||
action: 'wclp_test_license',
|
||||
nonce: wclpAdmin.editNonce,
|
||||
license_key: licenseKey,
|
||||
domain: domain
|
||||
},
|
||||
success: function(response) {
|
||||
$testLoading.hide();
|
||||
if (response.success) {
|
||||
var result = response.data;
|
||||
var html = '';
|
||||
|
||||
if (result.valid) {
|
||||
html = '<div class="notice notice-success inline"><p><strong>✓ <?php echo esc_js(__('License is VALID', 'wc-licensed-product')); ?></strong></p></div>';
|
||||
html += '<table class="widefat striped"><tbody>';
|
||||
html += '<tr><th><?php echo esc_js(__('Product', 'wc-licensed-product')); ?></th><td>' + escapeHtml(result.product_name || '-') + '</td></tr>';
|
||||
html += '<tr><th><?php echo esc_js(__('Version', 'wc-licensed-product')); ?></th><td>' + escapeHtml(result.version || '-') + '</td></tr>';
|
||||
if (result.expires_at) {
|
||||
html += '<tr><th><?php echo esc_js(__('Expires', 'wc-licensed-product')); ?></th><td>' + escapeHtml(result.expires_at) + '</td></tr>';
|
||||
} else {
|
||||
html += '<tr><th><?php echo esc_js(__('Expires', 'wc-licensed-product')); ?></th><td><?php echo esc_js(__('Lifetime', 'wc-licensed-product')); ?></td></tr>';
|
||||
}
|
||||
html += '</tbody></table>';
|
||||
} else {
|
||||
html = '<div class="notice notice-error inline"><p><strong>✗ <?php echo esc_js(__('License is INVALID', 'wc-licensed-product')); ?></strong></p></div>';
|
||||
html += '<table class="widefat striped"><tbody>';
|
||||
html += '<tr><th><?php echo esc_js(__('Error Code', 'wc-licensed-product')); ?></th><td><code>' + escapeHtml(result.error || 'unknown') + '</code></td></tr>';
|
||||
html += '<tr><th><?php echo esc_js(__('Message', 'wc-licensed-product')); ?></th><td>' + escapeHtml(result.message || '-') + '</td></tr>';
|
||||
html += '</tbody></table>';
|
||||
}
|
||||
|
||||
$testResultContent.html(html);
|
||||
$testResult.show();
|
||||
} else {
|
||||
$testResultContent.html('<div class="notice notice-error inline"><p>' + escapeHtml(response.data.message || 'Error') + '</p></div>');
|
||||
$testResult.show();
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
$testLoading.hide();
|
||||
$testResultContent.html('<div class="notice notice-error inline"><p><?php echo esc_js(__('Failed to test license. Please try again.', 'wc-licensed-product')); ?></p></div>');
|
||||
$testResult.show();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Close modals
|
||||
$('.wclp-modal-close, .wclp-modal-cancel').on('click', function() {
|
||||
$(this).closest('.wclp-modal').hide();
|
||||
});
|
||||
|
||||
$(window).on('click', function(e) {
|
||||
if ($(e.target).hasClass('wclp-modal')) {
|
||||
$(e.target).hide();
|
||||
}
|
||||
});
|
||||
|
||||
function escapeHtml(text) {
|
||||
if (!text) return '';
|
||||
var div = document.createElement('div');
|
||||
div.textContent = text;
|
||||
return div.innerHTML;
|
||||
}
|
||||
})(jQuery);
|
||||
</script>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user