Skip to content

Commit 31a193f

Browse files
committed
updated expiration display logic
1 parent 559ea42 commit 31a193f

3 files changed

Lines changed: 82 additions & 12 deletions

File tree

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44

55
Ensure that your website is running PHP 8 or later. This plugin is confirmed to be working with PHP 8.3.
66

7-
1. Clone this repo.
8-
2. Zip `software-licensor-wp-plugin`
9-
3. Upload the plugin to your website.
7+
1. Clone this repo and zip `software-licensor-wp-plugin`, or download the latest release.
8+
3. Upload the plugin (the zip file) to your website.
109
4. Navigate from the admin dashboard to `WooCommerce>Settings>Integration>Software Licensor`.
1110
5. Fill out the form and click save. If the form is missing data, the request might not go through and you won't be able to see a store ID in the next step.
1211
6. Navigate from the admin dashboard to `Software Licensor>Software Licensor`. Verify that you can see a roughly 64-character long string at the top under `Store ID`. You will need to include this `store_id` in the client side code.

software-licensor-wp-plugin/Software-Licensor-Integration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Description: A plugin for handling software licenses through Software Licensor
66
* Author: Noah Stiltner
77
* Author URI: https://www.alteredbrainchemistry.com
8-
* Version: 1.1
8+
* Version: 1.1.1
99
* Requires PHP: 8.0
1010
*
1111
* This program is free software: you can redistribute it and/or modify

software-licensor-wp-plugin/includes/class-wc-software-licensor-integration.php

Lines changed: 79 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -125,25 +125,23 @@ function get_license_data_html() {
125125
$machines = [];
126126
$license_type = $product_data->getLicenseType();
127127
$expiration = $product_data->getExpirationOrRenewal();
128-
if (is_numeric($expiration) && $expiration > 0) {
129-
$expiration = date("d M Y", $expiration);
130-
}
128+
131129
$offline_machines = $product_data->getOfflineMachines();
132130
$online_machines = $product_data->getOnlineMachines();
133131
$machine_limit = $product_data->getMachineLimit();
134132
$machine_count = count($offline_machines) + count($online_machines);
135133

136134
foreach ($offline_machines as $index => $m) {
137135
array_push($machines, [
138-
'id' => $m->getId(),
136+
'id' => substr((string) $m->getId(), 0, 10),
139137
'os' => $m->getOs(),
140138
'computer_name' => $m->getComputerName(),
141139
'activation_type' => 'offline'
142140
]);
143141
}
144142
foreach ($online_machines as $index => $m) {
145143
array_push($machines, [
146-
'id' => $m->getId(),
144+
'id' => substr((string) $m->getId(), 0, 10),
147145
'os' => $m->getOs(),
148146
'computer_name' => $m->getComputerName(),
149147
'activation_type' => 'online'
@@ -210,7 +208,11 @@ function get_license_data_html() {
210208
$output_html .= '<tr class="SL-product-row" data-index="' . htmlspecialchars($item['index']) . '">';
211209
$output_html .= '<td>' . stripslashes(htmlspecialchars($item['product_name'])) . '</td>';
212210
$output_html .= '<td>' . htmlspecialchars($item['license_type']) . '</td>';
213-
$output_html .= '<td>' . htmlspecialchars($item['expiration']) . '</td>';
211+
if ($item['expiration'] != '0' && $item['expiration'] != 0 && is_numeric($item['expiration'])) {
212+
$output_html .= '<td class="sl-expiration" data-ts="' . esc_attr($item['expiration']) . '"></td>';
213+
} else {
214+
$output_html .= '<td>' . htmlspecialchars($item['expiration']) . '</td>';
215+
}
214216
$output_html .= '<td>' . htmlspecialchars($item['machine_count']) . '/' . htmlspecialchars($item['machine_limit']) . '</td>';
215217
$output_html .= '</tr>';
216218

@@ -270,6 +272,24 @@ function regenerateLicense() {
270272
}
271273
});
272274
});
275+
276+
document.querySelectorAll(".sl-expiration").forEach(function(el) {
277+
const ts = parseInt(el.dataset.ts, 10);
278+
279+
if (!isNaN(ts) && ts > 0) {
280+
const date = new Date(ts * 1000);
281+
282+
el.textContent = date.toLocaleString(undefined, {
283+
day: "2-digit",
284+
month: "short",
285+
year: "numeric",
286+
hour: "2-digit",
287+
minute: "2-digit"
288+
});
289+
} else {
290+
el.textContent = "—";
291+
}
292+
});
273293
});
274294
</script></div>';
275295

@@ -406,7 +426,17 @@ public function init_form_fields() {
406426
'share_customer_info' => array(
407427
'title' => __( 'Share Customer Info', 'software-licensor' ),
408428
'type' => 'checkbox',
409-
'description' => __( 'Optionally share customer info with Software Licensor. Sharing this will enable the possibility of customer\'s contact information to be visible in the licensed software (you would also need to display it with your client side code). We do not sell or share personal customer information, and the information will be encrypted in transit and at rest. If you check this box, you will need to include a statement in your privacy policy that Software Licensor is one of the 3rd parties that you are sharing customer data with. The collected data primarily includes names and emails, and can also include computer names, OS names, MAC addresses, and some hardware information.', 'software-licensor' ),
429+
'description' => __( 'Optionally share customer info with ' .
430+
'Software Licensor. Sharing this will enable the ' .
431+
'possibility of customer\'s contact information to be ' .
432+
'visible in your licensed software (you would also need ' .
433+
'to display it with your client side code). We do not ' .
434+
'sell or share personal customer information, and the ' .
435+
'information will be encrypted in transit and at rest. ' .
436+
'If you check this box, you will need to include a ' .
437+
'statement in your privacy policy that Software Licensor ' .
438+
'is one of the 3rd parties that you are sharing customer ' .
439+
'data with. The collected data primarily includes names and emails, and can also include computer names, OS names, MAC addresses, and some hardware information.', 'software-licensor' ),
410440
'default' => '',
411441
'label' => 'Share customer info',
412442
),
@@ -440,7 +470,6 @@ public function init_form_fields() {
440470
*/
441471
public function process_admin_options()
442472
{
443-
echo 'Reached process_admin_options() function';
444473
$all_settings_valid = true;
445474
$settings = $this->get_form_fields();
446475

@@ -498,6 +527,16 @@ function software_licensor_admin_menus() {
498527
'dashicons-admin-network'
499528
);
500529

530+
// store registration
531+
add_submenu_page(
532+
'software-licensor',
533+
'Store Registration',
534+
'Store Registration',
535+
'manage_options',
536+
'software-licensor-store-registration',
537+
array($this, 'software_licensor_store_registration_page')
538+
);
539+
501540
// product creation page
502541
add_submenu_page(
503542
'software-licensor',
@@ -521,6 +560,38 @@ function software_licensor_admin_menus() {
521560
add_action('load-' . $import_export_page, array($this, 'user_export_handler'));
522561
}
523562

563+
public function software_licensor_store_registration_page() {
564+
if (!current_user_can('manage_options')) {
565+
wp_die(__('You do not have sufficient permissions to access this page.', 'software-licensor'));
566+
}
567+
568+
if (
569+
isset($_POST['software_licensor_store_registration_nonce']) &&
570+
wp_verify_nonce(
571+
sanitize_text_field(wp_unslash($_POST['software_licensor_store_registration_nonce'])),
572+
'software_licensor_store_registration_save'
573+
)
574+
) {
575+
$this->process_admin_options();
576+
echo '<div class="updated"><p>' . esc_html__('Settings saved.', 'software-licensor') . '</p></div>';
577+
}
578+
579+
echo '<div class="wrap">';
580+
echo '<h1>' . esc_html__('Store Registration', 'software-licensor') . '</h1>';
581+
echo '<form method="post" action="">';
582+
583+
wp_nonce_field('software_licensor_store_registration_save', 'software_licensor_store_registration_nonce');
584+
585+
echo '<table class="form-table">';
586+
$this->generate_settings_html();
587+
echo '</table>';
588+
589+
submit_button();
590+
591+
echo '</form>';
592+
echo '</div>';
593+
}
594+
524595
/**
525596
* Prevents HTML from being appended to Exported data.
526597
*/

0 commit comments

Comments
 (0)