Skip to content

Commit b1db15e

Browse files
authored
Feature Enhancement: Buttons, PHP 8.1, and Check License Errors (#3)
2 parents d636c51 + a272628 commit b1db15e

File tree

7 files changed

+1598
-393
lines changed

7 files changed

+1598
-393
lines changed

assets/js/licensemanager.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
'use strict'
44

55
$(document).ready(function () {
6-
$('a[id^="EddSoftwareLicenseManagerButton"]:not(:disabled)').on('click', function (e) {
6+
$('a[id^="EddSoftwareLicenseManagerButton"]:not(.disabled)').on('click', function (e) {
77
e.preventDefault()
88
const $this = $(this)
99
const $element = $('input[name$="[' + $this.data('plugin_id') + ']"]')
@@ -27,10 +27,14 @@
2727
$('<img class="EddLicenseLoader" src="' + EddLicenseManager.loading + '" height="16" width="16">').insertAfter($this)
2828
},
2929
success: function (response) {
30+
$('img[class="EddLicenseLoader"]').remove()
3031
if (typeof response.success !== 'undefined' && response.success) {
31-
$this.closest('form').submit()
32+
if ($this.data('action') === 'check_license') {
33+
window.alert(response.data)
34+
return
35+
}
36+
$('input#submit').trigger('click')
3237
}
33-
$('img[class="EddLicenseLoader"]').remove()
3438
},
3539
fail: function (response) {
3640
$this.attr('disabled', false)

composer.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818
},
1919
"optimize-autoloader": true,
2020
"platform": {
21-
"php": "8.0"
21+
"php": "8.1"
2222
},
2323
"preferred-install": "dist",
2424
"sort-packages": true
2525
},
2626
"require": {
27-
"php": "^8.0",
27+
"php": "^8.1",
2828
"composer/installers": "~2.0",
2929
"dwnload/wp-settings-api": "^3.9",
3030
"thefrosty/wp-utilities": "^3.2"
@@ -35,11 +35,12 @@
3535
"phpcompatibility/php-compatibility": "^9.3",
3636
"phpunit/php-code-coverage": "^9",
3737
"phpunit/phpunit": "^9",
38-
"roots/wordpress": "^6.4",
38+
"roave/security-advisories": "dev-latest",
39+
"roots/wordpress": "^6.7",
3940
"squizlabs/php_codesniffer": "^3.2",
40-
"symfony/var-dumper": "^5.4 || ^6.2",
41-
"wp-phpunit/wp-phpunit": "^6.3",
42-
"yoast/phpunit-polyfills": "^2.0"
41+
"symfony/var-dumper": "^6.4 || ^7.2",
42+
"wp-phpunit/wp-phpunit": "^6.7",
43+
"yoast/phpunit-polyfills": "^3.0 || ^4.0"
4344
},
4445
"autoload": {
4546
"psr-4": {

composer.lock

Lines changed: 1555 additions & 342 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Edd/AbstractLicenceManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function buildSubmitButton(string $plugin_id, string $class, string $acti
5757
};
5858

5959
\printf(
60-
'<a href="javascript:;" id="EddSoftwareLicenseManagerButton_%3$s" class="button %2$s" data-action="%3$s" data-plugin_id="%5$s" data-status="%4$s">%1$s</a>',
60+
'<a id="EddSoftwareLicenseManagerButton_%3$s" class="button %2$s" data-action="%3$s" data-plugin_id="%5$s" data-status="%4$s">%1$s</a>',
6161
$text,
6262
$class,
6363
$action,

src/Edd/Models/CheckLicense.php

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,8 @@ class CheckLicense extends LicenseStatus
2323
/** @var int $site_count */
2424
private int $site_count;
2525

26-
/** @var int $activations_left */
27-
private int $activations_left;
28-
29-
/** @var int $price_id */
30-
private int $price_id;
26+
/** @var int|string $activations_left */
27+
private int|string $activations_left;
3128

3229
/**
3330
* @param bool $success
@@ -94,34 +91,18 @@ public function getSiteCount(): int
9491
}
9592

9693
/**
97-
* @param int $activations_left
94+
* @param int|string $activations_left
9895
*/
99-
public function setActivationsLeft(int $activations_left): void
96+
public function setActivationsLeft(int|string $activations_left): void
10097
{
10198
$this->activations_left = $activations_left;
10299
}
103100

104101
/**
105102
* @return int
106103
*/
107-
public function getActivationsLeft(): int
104+
public function getActivationsLeft(): int|string
108105
{
109106
return $this->activations_left;
110107
}
111-
112-
/**
113-
* @param mixed $price_id
114-
*/
115-
public function setPriceId(int $price_id): void
116-
{
117-
$this->price_id = $price_id;
118-
}
119-
120-
/**
121-
* @return mixed
122-
*/
123-
public function getPriceId(): int
124-
{
125-
return $this->price_id;
126-
}
127108
}

src/Edd/Models/LicenseStatus.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ abstract class LicenseStatus extends BaseModel
2323
public const LICENSE_FAILED = 'inactive';
2424
public const LICENSE_INACTIVE = 'inactive';
2525
public const LICENSE_INVALID = 'invalid';
26+
public const LICENSE_VALID = 'valid';
2627
public const LICENSE_CHECK_LICENSE = 'check_license';
2728
public const LICENSE_SITE_INACTIVE = 'site_inactive';
2829

views/license.php

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,48 +11,53 @@
1111
wp_die();
1212
}
1313

14-
if (!isset($plugin_id) || !isset($section_id)) {
14+
if (!isset($plugin_id, $section_id)) {
1515
return;
1616
}
1717
$license_key = Options::getOption($plugin_id, $section_id);
1818
$license_data = get_option(AbstractLicenceManager::LICENSE_SETTING, []);
1919
$license_expires = $license_data[$plugin_id]['expires'] ?? '';
2020
$license_status = $license_data[$plugin_id]['status'] ?? LicenseStatus::LICENSE_INACTIVE;
21-
21+
$active_or_valid = in_array($license_status, [LicenseStatus::LICENSE_ACTIVE, LicenseStatus::LICENSE_VALID], true);
2222
ob_start();
2323

2424
echo "<div class='EddSoftwareLicenseManager'>";
2525
printf('License Status: <span class="license-status %1$s">%1$s</span>', $license_status);
2626
if (!empty($license_expires)) {
2727
printf(
2828
' &mdash; License Expires: <span class="license-expires">%1$s</span>',
29-
date_i18n(get_option('date_format'), strtotime($license_expires))
29+
$license_expires === 'lifetime' ?
30+
'Never (lifetime)' :
31+
date_i18n(get_option('date_format'), strtotime($license_expires))
3032
);
3133
}
3234

3335
echo '<br><hr>';
3436

35-
if (!empty($license_data) && $license_status === LicenseStatus::LICENSE_ACTIVE) {
36-
$this->buildSubmitButton(
37-
$plugin_id,
38-
'button-primary',
39-
LicenseStatus::LICENSE_DEACTIVATE,
40-
$license_status,
41-
);
37+
$this->buildSubmitButton(
38+
$plugin_id,
39+
'button-primary',
40+
LicenseStatus::LICENSE_ACTIVATE,
41+
$license_status
42+
);
43+
44+
echo '&nbsp;&nbsp;';
45+
46+
$this->buildSubmitButton(
47+
$plugin_id,
48+
$active_or_valid ? 'button-primary' : 'button-secondary disabled',
49+
$license_status === LicenseStatus::LICENSE_DEACTIVATED ? LicenseStatus::LICENSE_ACTIVATE : LicenseStatus::LICENSE_DEACTIVATE,
50+
$license_status,
51+
);
52+
53+
if (!$active_or_valid) {
4254
echo '&nbsp;&nbsp;';
4355
$this->buildSubmitButton(
4456
$plugin_id,
4557
'button-secondary',
4658
LicenseStatus::LICENSE_CHECK_LICENSE,
4759
$license_status
4860
);
49-
} else {
50-
$this->buildSubmitButton(
51-
$plugin_id,
52-
empty($license_key) ? 'button-primary disabled' : 'button-primary',
53-
LicenseStatus::LICENSE_ACTIVATE,
54-
$license_status
55-
);
5661
}
5762
echo '</div>';
5863

0 commit comments

Comments
 (0)