PluginProbe
RT Mega Menu – Mega Menu Builder for Elementor & Gutenberg / trunk
RT Mega Menu – Mega Menu Builder for Elementor & Gutenberg vtrunk
1.5.3 1.5.2 1.5.1 1.5.0 1.4.8 1.4.9 1.4.7 1.4.6 1.4.5 trunk 1.0.9 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.2.1 1.2.2 1.2.3 All 47 releases
rt-mega-menu / apps / License.php

License.php in RT Mega Menu – Mega Menu Builder for Elementor & Gutenberg trunk, at apps/License.php

810 lines 25.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Appsero;
4
5 /**
6 * Appsero License Checker
7 *
8 * This class will check, active and deactive license
9 */
10 class License {
11
12 /**
13 * AppSero\Client
14 *
15 * @var object
16 */
17 protected $client;
18
19 /**
20 * Arguments of create menu
21 *
22 * @var array
23 */
24 protected $menu_args;
25
26 /**
27 * `option_name` of `wp_options` table
28 *
29 * @var string
30 */
31 protected $option_key;
32
33 /**
34 * Error message of HTTP request
35 *
36 * @var string
37 */
38 public $error;
39
40 /**
41 * Success message on form submit
42 *
43 * @var string
44 */
45 public $success;
46
47 /**
48 * Corn schedule hook name
49 *
50 * @var string
51 */
52 protected $schedule_hook;
53
54 /**
55 * Set value for valid license
56 *
57 * @var bool
58 */
59 private $is_valid_license = null;
60
61 /**
62 * Initialize the class
63 *
64 * @param Client $client
65 */
66 public function __construct( Client $client ) {
67 $this->client = $client;
68
69 $this->option_key = 'appsero_' . md5( $this->client->slug ) . '_manage_license';
70
71 $this->schedule_hook = $this->client->slug . '_license_check_event';
72
73 // Creating WP Ajax Endpoint to refresh license remotely
74 add_action( 'wp_ajax_appsero_refresh_license_' . $this->client->hash, [ $this, 'refresh_license_api' ] );
75
76 // Run hook to check license status daily
77 add_action( $this->schedule_hook, [ $this, 'check_license_status' ] );
78
79 // Active/Deactive corn schedule
80 $this->run_schedule();
81 }
82
83 /**
84 * Set the license option key.
85 *
86 * If someone wants to override the default generated key.
87 *
88 * @param string $key
89 *
90 * @since 1.3.0
91 *
92 * @return License
93 */
94 public function set_option_key( $key ) {
95 $this->option_key = $key;
96
97 return $this;
98 }
99
100 /**
101 * Get the license key
102 *
103 * @since 1.3.0
104 *
105 * @return string|null
106 */
107 public function get_license() {
108 return get_option( $this->option_key, null );
109 }
110
111 /**
112 * Check license
113 *
114 * @return array
115 */
116 public function check( $license_key ) {
117 $route = 'public/license/' . $this->client->hash . '/check';
118
119 return $this->send_request( $license_key, $route );
120 }
121
122 /**
123 * Active a license
124 *
125 * @return array
126 */
127 public function activate( $license_key ) {
128 $route = 'public/license/' . $this->client->hash . '/activate';
129
130 return $this->send_request( $license_key, $route );
131 }
132
133 /**
134 * Deactivate a license
135 *
136 * @return array
137 */
138 public function deactivate( $license_key ) {
139 $route = 'public/license/' . $this->client->hash . '/deactivate';
140
141 return $this->send_request( $license_key, $route );
142 }
143
144 /**
145 * Send common request
146 *
147 * @return array
148 */
149 protected function send_request( $license_key, $route ) {
150 $params = [
151 'license_key' => $license_key,
152 'url' => esc_url( home_url() ),
153 'is_local' => $this->client->is_local_server(),
154 ];
155
156 $response = $this->client->send_request( $params, $route, true );
157
158 if ( is_wp_error( $response ) ) {
159 return [
160 'success' => false,
161 'error' => $response->get_error_message(),
162 ];
163 }
164
165 $response = json_decode( wp_remote_retrieve_body( $response ), true );
166
167 if ( empty( $response ) || isset( $response['exception'] ) ) {
168 return [
169 'success' => false,
170 'error' => $this->client->__trans( 'Unknown error occurred, Please try again.' ),
171 ];
172 }
173
174 if ( isset( $response['errors'] ) && isset( $response['errors']['license_key'] ) ) {
175 $response = [
176 'success' => false,
177 'error' => $response['errors']['license_key'][0],
178 ];
179 }
180
181 return $response;
182 }
183
184 /**
185 * License Refresh Endpoint
186 */
187 public function refresh_license_api() {
188 $this->check_license_status();
189
190 wp_send_json_success(
191 [
192 'message' => 'License refreshed successfully.',
193 ],
194 200
195 );
196 }
197
198 /**
199 * Add settings page for license
200 *
201 * @param array $args
202 *
203 * @return void
204 */
205 public function add_settings_page( $args = [] ) {
206 $defaults = [
207 'type' => 'menu', // Can be: menu, options, submenu
208 'page_title' => 'Manage License',
209 'menu_title' => 'Manage License',
210 'capability' => 'manage_options',
211 'menu_slug' => $this->client->slug . '-manage-license',
212 'icon_url' => '',
213 'position' => null,
214 'parent_slug' => '',
215 ];
216
217 $this->menu_args = wp_parse_args( $args, $defaults );
218
219 add_action( 'admin_menu', [ $this, 'admin_menu' ], 99 );
220 }
221
222 /**
223 * Admin Menu hook
224 *
225 * @return void
226 */
227 public function admin_menu() {
228 switch ( $this->menu_args['type'] ) {
229 case 'menu':
230 $this->create_menu_page();
231 break;
232
233 case 'submenu':
234 $this->create_submenu_page();
235 break;
236
237 case 'options':
238 $this->create_options_page();
239 break;
240 }
241 }
242
243 /**
244 * License menu output
245 */
246 public function menu_output() {
247 // process form data if submitted
248 if ( isset( $_POST['_nonce'] ) && wp_verify_nonce( sanitize_key( wp_unslash( $_POST['_nonce'] ) ), $this->client->name ) ) {
249 $form_data = [
250 '_nonce' => sanitize_key( wp_unslash( $_POST['_nonce'] ) ),
251 '_action' => isset( $_POST['_action'] ) ? sanitize_text_field( wp_unslash( $_POST['_action'] ) ) : '',
252 'license_key' => isset( $_POST['license_key'] ) ? sanitize_text_field( wp_unslash( $_POST['license_key'] ) ) : '',
253 ];
254 $this->license_form_submit( $form_data );
255 }
256
257 $license = $this->get_license();
258 $action = ( $license && isset( $license['status'] ) && 'activate' === $license['status'] ) ? 'deactive' : 'active';
259 $this->licenses_style();
260 ?>
261
262 <div class="wrap appsero-license-settings-wrapper">
263 <h1>License Settings</h1>
264
265 <?php
266 $this->show_license_page_notices();
267 do_action( 'before_appsero_license_section' );
268 ?>
269
270 <div class="appsero-license-settings appsero-license-section">
271 <?php $this->show_license_page_card_header( $license ); ?>
272
273 <div class="appsero-license-details">
274 <p>
275 <?php printf( $this->client->__trans( 'Activate <strong>%s</strong> by your license key to get professional support and automatic update from your WordPress dashboard.' ), $this->client->name ); ?>
276 </p>
277 <form method="post" novalidate="novalidate" spellcheck="false">
278 <input type="hidden" name="_action" value="<?php echo $action; ?>">
279 <input type="hidden" name="_nonce" value="<?php echo wp_create_nonce( $this->client->name ); ?>">
280 <div class="license-input-fields">
281 <div class="license-input-key">
282 <svg enable-background="new 0 0 512 512" version="1.1" viewBox="0 0 512 512" xml:space="preserve" xmlns="http://www.w3.org/2000/svg">
283 <path d="m463.75 48.251c-64.336-64.336-169.01-64.335-233.35 1e-3 -43.945 43.945-59.209 108.71-40.181 167.46l-185.82 185.82c-2.813 2.813-4.395 6.621-4.395 10.606v84.858c0 8.291 6.709 15 15 15h84.858c3.984 0 7.793-1.582 10.605-4.395l21.211-21.226c3.237-3.237 4.819-7.778 4.292-12.334l-2.637-22.793 31.582-2.974c7.178-0.674 12.847-6.343 13.521-13.521l2.974-31.582 22.793 2.651c4.233 0.571 8.496-0.85 11.704-3.691 3.193-2.856 5.024-6.929 5.024-11.206v-27.929h27.422c3.984 0 7.793-1.582 10.605-4.395l38.467-37.958c58.74 19.043 122.38 4.929 166.33-39.046 64.336-64.335 64.336-169.01 0-233.35zm-42.435 106.07c-17.549 17.549-46.084 17.549-63.633 0s-17.549-46.084 0-63.633 46.084-17.549 63.633 0 17.548 46.084 0 63.633z"/>
284 </svg>
285 <input type="text" value="<?php echo $this->get_input_license_value( $action, $license ); ?>"
286 placeholder="<?php echo esc_attr( $this->client->__trans( 'Enter your license key to activate' ) ); ?>" name="license_key"
287 <?php echo ( 'deactive' === $action ) ? 'readonly="readonly"' : ''; ?>
288 />
289 </div>
290 <button type="submit" name="submit" class="<?php echo 'deactive' === $action ? 'deactive-button' : ''; ?>">
291 <?php echo $action === 'active' ? $this->client->__trans( 'Activate License' ) : $this->client->__trans( 'Deactivate License' ); ?>
292 </button>
293 </div>
294 </form>
295
296 <?php
297 if ( 'deactive' === $action && isset( $license['remaining'] ) ) {
298 $this->show_active_license_info( $license );
299 }
300 ?>
301 </div>
302 </div> <!-- /.appsero-license-settings -->
303
304 <?php do_action( 'after_appsero_license_section' ); ?>
305 </div>
306 <?php
307 }
308
309 /**
310 * License form submit
311 */
312 public function license_form_submit( $form_data = array() ) {
313 if ( ! isset( $form_data['_nonce'] ) ) {
314 return;
315 }
316
317 if ( ! wp_verify_nonce( sanitize_key( wp_unslash( $form_data['_nonce'] ) ), $this->client->name ) ) {
318 $this->error = $this->client->__trans( 'Nonce vefification failed.' );
319
320 return;
321 }
322
323 if ( ! current_user_can( 'manage_options' ) ) {
324 $this->error = $this->client->__trans( 'You don\'t have permission to manage license.' );
325
326 return;
327 }
328
329 $license_key = ! empty( $form_data['license_key'] ) ? sanitize_text_field( wp_unslash( $form_data['license_key'] ) ) : '';
330 $action = ! empty( $form_data['_action'] ) ? sanitize_text_field( wp_unslash( $form_data['_action'] ) ) : '';
331
332 switch ( $action ) {
333 case 'active':
334 $this->active_client_license( $license_key );
335 break;
336
337 case 'deactive':
338 $this->deactive_client_license();
339 break;
340
341 case 'refresh':
342 $this->refresh_client_license();
343 break;
344 }
345 }
346
347 /**
348 * Check license status on schedule
349 */
350 public function check_license_status() {
351 $license = $this->get_license();
352
353 if ( isset( $license['key'] ) && ! empty( $license['key'] ) ) {
354 $response = $this->check( $license['key'] );
355
356 if ( isset( $response['success'] ) && $response['success'] ) {
357 $license['status'] = 'activate';
358 $license['remaining'] = $response['remaining'];
359 $license['activation_limit'] = $response['activation_limit'];
360 $license['expiry_days'] = $response['expiry_days'];
361 $license['title'] = $response['title'];
362 $license['source_id'] = $response['source_identifier'];
363 $license['recurring'] = $response['recurring'];
364 } else {
365 $license['status'] = 'deactivate';
366 $license['expiry_days'] = 0;
367 }
368
369 update_option( $this->option_key, $license, false );
370 }
371 }
372
373 /**
374 * Check this is a valid license
375 */
376 public function is_valid() {
377 if ( null !== $this->is_valid_license ) {
378 return $this->is_valid_license;
379 }
380
381 $license = $this->get_license();
382
383 if ( ! empty( $license['key'] ) && isset( $license['status'] ) && $license['status'] === 'activate' ) {
384 $this->is_valid_license = true;
385 } else {
386 $this->is_valid_license = false;
387 }
388
389 return $this->is_valid_license;
390 }
391
392 /**
393 * Check this is a valid license
394 */
395 public function is_valid_by( $option, $value ) {
396 $license = $this->get_license();
397
398 if ( ! empty( $license['key'] ) && isset( $license['status'] ) && $license['status'] === 'activate' ) {
399 if ( isset( $license[ $option ] ) && $license[ $option ] === $value ) {
400 return true;
401 }
402 }
403
404 return false;
405 }
406
407 /**
408 * Styles for licenses page
409 */
410 private function licenses_style() {
411 ?>
412 <style type="text/css">
413 .appsero-license-section {
414 width: 100%;
415 max-width: 1100px;
416 min-height: 1px;
417 box-sizing: border-box;
418 }
419 .appsero-license-settings {
420 background-color: #fff;
421 box-shadow: 0px 3px 10px rgba(16, 16, 16, 0.05);
422 }
423 .appsero-license-settings * {
424 box-sizing: border-box;
425 }
426 .appsero-license-title {
427 background-color: #F8FAFB;
428 border-bottom: 2px solid #EAEAEA;
429 display: flex;
430 align-items: center;
431 padding: 10px 20px;
432 }
433 .appsero-license-title svg {
434 width: 30px;
435 height: 30px;
436 fill: #0082BF;
437 }
438 .appsero-license-title span {
439 font-size: 17px;
440 color: #444444;
441 margin-left: 10px;
442 }
443 .appsero-license-details {
444 padding: 20px;
445 }
446 .appsero-license-details p {
447 font-size: 15px;
448 margin: 0 0 20px 0;
449 }
450 .license-input-key {
451 position: relative;
452 flex: 0 0 72%;
453 max-width: 72%;
454 }
455 .license-input-key input {
456 background-color: #F9F9F9;
457 padding: 10px 15px 10px 48px;
458 border: 1px solid #E8E5E5;
459 border-radius: 3px;
460 height: 45px;
461 font-size: 16px;
462 color: #71777D;
463 width: 100%;
464 box-shadow: 0 0 0 transparent;
465 }
466 .license-input-key input:focus {
467 outline: 0 none;
468 border: 1px solid #E8E5E5;
469 box-shadow: 0 0 0 transparent;
470 }
471 .license-input-key svg {
472 width: 22px;
473 height: 22px;
474 fill: #0082BF;
475 position: absolute;
476 left: 14px;
477 top: 13px;
478 }
479 .license-input-fields {
480 display: flex;
481 justify-content: space-between;
482 margin-bottom: 30px;
483 max-width: 850px;
484 width: 100%;
485 }
486 .license-input-fields button {
487 color: #fff;
488 font-size: 17px;
489 padding: 8px;
490 height: 46px;
491 background-color: #0082BF;
492 border-radius: 3px;
493 cursor: pointer;
494 flex: 0 0 25%;
495 max-width: 25%;
496 border: 1px solid #0082BF;
497 }
498 .license-input-fields button.deactive-button {
499 background-color: #E40055;
500 border-color: #E40055;
501 }
502 .license-input-fields button:focus {
503 outline: 0 none;
504 }
505 .active-license-info {
506 display: flex;
507 }
508 .single-license-info {
509 min-width: 220px;
510 flex: 0 0 30%;
511 }
512 .single-license-info h3 {
513 font-size: 18px;
514 margin: 0 0 12px 0;
515 }
516 .single-license-info p {
517 margin: 0;
518 color: #00C000;
519 }
520 .single-license-info p.occupied {
521 color: #E40055;
522 }
523 .appsero-license-right-form {
524 margin-left: auto;
525 }
526 .appsero-license-refresh-button {
527 padding: 6px 10px 4px 10px;
528 border: 1px solid #0082BF;
529 border-radius: 3px;
530 margin-left: auto;
531 background-color: #0082BF;
532 color: #fff;
533 cursor: pointer;
534 }
535 .appsero-license-refresh-button .dashicons {
536 color: #fff;
537 margin-left: 0;
538 }
539 </style>
540 <?php
541 }
542
543 /**
544 * Show active license information
545 */
546 private function show_active_license_info( $license ) {
547 ?>
548 <div class="active-license-info">
549 <div class="single-license-info">
550 <h3><?php $this->client->_etrans( 'Activations Remaining' ); ?></h3>
551 <?php if ( empty( $license['activation_limit'] ) ) { ?>
552 <p><?php $this->client->_etrans( 'Unlimited' ); ?></p>
553 <?php } else { ?>
554 <p class="<?php echo $license['remaining'] ? '' : 'occupied'; ?>">
555 <?php printf( $this->client->__trans( '%1$d out of %2$d' ), $license['remaining'], $license['activation_limit'] ); ?>
556 </p>
557 <?php } ?>
558 </div>
559 <div class="single-license-info">
560 <h3><?php $this->client->_etrans( 'Expires in' ); ?></h3>
561 <?php
562 if ( false !== $license['expiry_days'] ) {
563 $occupied = $license['expiry_days'] > 21 ? '' : 'occupied';
564 echo '<p class="' . $occupied . '">' . $license['expiry_days'] . ' days</p>';
565 } else {
566 echo '<p>' . $this->client->__trans( 'Never' ) . '</p>';
567 }
568 ?>
569 </div>
570 </div>
571 <?php
572 }
573
574 /**
575 * Show license settings page notices
576 */
577 private function show_license_page_notices() {
578 if ( ! empty( $this->error ) ) {
579 ?>
580 <div class="notice notice-error is-dismissible appsero-license-section">
581 <p><?php echo $this->error; ?></p>
582 </div>
583 <?php
584 }
585
586 if ( ! empty( $this->success ) ) {
587 ?>
588 <div class="notice notice-success is-dismissible appsero-license-section">
589 <p><?php echo $this->success; ?></p>
590 </div>
591 <?php
592 }
593 echo '<br />';
594 }
595
596 /**
597 * Card header
598 */
599 private function show_license_page_card_header( $license ) {
600 ?>
601 <div class="appsero-license-title">
602 <svg enable-background="new 0 0 299.995 299.995" version="1.1" viewBox="0 0 300 300" xml:space="preserve" xmlns="http://www.w3.org/2000/svg">
603 <path d="m150 161.48c-8.613 0-15.598 6.982-15.598 15.598 0 5.776 3.149 10.807 7.817 13.505v17.341h15.562v-17.341c4.668-2.697 7.817-7.729 7.817-13.505 0-8.616-6.984-15.598-15.598-15.598z"/>
604 <path d="m150 85.849c-13.111 0-23.775 10.665-23.775 23.775v25.319h47.548v-25.319c-1e-3 -13.108-10.665-23.775-23.773-23.775z"/>
605 <path d="m150 1e-3c-82.839 0-150 67.158-150 150 0 82.837 67.156 150 150 150s150-67.161 150-150c0-82.839-67.161-150-150-150zm46.09 227.12h-92.173c-9.734 0-17.626-7.892-17.626-17.629v-56.919c0-8.491 6.007-15.582 14.003-17.25v-25.697c0-27.409 22.3-49.711 49.711-49.711 27.409 0 49.709 22.3 49.709 49.711v25.697c7.993 1.673 14 8.759 14 17.25v56.919h2e-3c0 9.736-7.892 17.629-17.626 17.629z"/>
606 </svg>
607 <span><?php echo $this->client->__trans( 'Activate License' ); ?></span>
608
609 <?php if ( $license && $license['key'] ) { ?>
610 <form method="post" class="appsero-license-right-form" novalidate="novalidate" spellcheck="false">
611 <input type="hidden" name="_action" value="refresh">
612 <input type="hidden" name="_nonce" value="<?php echo wp_create_nonce( $this->client->name ); ?>">
613 <button type="submit" name="submit" class="appsero-license-refresh-button">
614 <span class="dashicons dashicons-update"></span>
615 <?php echo $this->client->__trans( 'Refresh License' ); ?>
616 </button>
617 </form>
618 <?php } ?>
619
620 </div>
621 <?php
622 }
623
624 /**
625 * Active client license
626 */
627 private function active_client_license( $license_key ) {
628 if ( empty( $license_key ) ) {
629 $this->error = $this->client->__trans( 'The license key field is required.' );
630
631 return;
632 }
633
634 $response = $this->activate( $license_key );
635
636 if ( ! $response['success'] ) {
637 $this->error = $response['error'] ? $response['error'] : $this->client->__trans( 'Unknown error occurred.' );
638
639 return;
640 }
641
642 $data = [
643 'key' => $license_key,
644 'status' => 'activate',
645 'remaining' => $response['remaining'],
646 'activation_limit' => $response['activation_limit'],
647 'expiry_days' => $response['expiry_days'],
648 'title' => $response['title'],
649 'source_id' => $response['source_identifier'],
650 'recurring' => $response['recurring'],
651 ];
652
653 update_option( $this->option_key, $data, false );
654
655 $this->success = $this->client->__trans( 'License activated successfully.' );
656 }
657
658 /**
659 * Deactive client license
660 */
661 private function deactive_client_license() {
662 $license = $this->get_license();
663
664 if ( empty( $license['key'] ) ) {
665 $this->error = $this->client->__trans( 'License key not found.' );
666
667 return;
668 }
669
670 $response = $this->deactivate( $license['key'] );
671
672 $data = [
673 'key' => '',
674 'status' => 'deactivate',
675 ];
676
677 update_option( $this->option_key, $data, false );
678
679 if ( ! $response['success'] ) {
680 $this->error = $response['error'] ? $response['error'] : $this->client->__trans( 'Unknown error occurred.' );
681
682 return;
683 }
684
685 $this->success = $this->client->__trans( 'License deactivated successfully.' );
686 }
687
688 /**
689 * Refresh Client License
690 */
691 private function refresh_client_license() {
692 $license = $this->get_license();
693
694 if ( ! $license || ! isset( $license['key'] ) || empty( $license['key'] ) ) {
695 $this->error = $this->client->__trans( 'License key not found' );
696
697 return;
698 }
699
700 $this->check_license_status();
701
702 $this->success = $this->client->__trans( 'License refreshed successfully.' );
703 }
704
705 /**
706 * Add license menu page
707 */
708 private function create_menu_page() {
709 call_user_func(
710 'add_menu_page',
711 $this->menu_args['page_title'],
712 $this->menu_args['menu_title'],
713 $this->menu_args['capability'],
714 $this->menu_args['menu_slug'],
715 [ $this, 'menu_output' ],
716 $this->menu_args['icon_url'],
717 $this->menu_args['position']
718 );
719 }
720
721 /**
722 * Add submenu page
723 */
724 private function create_submenu_page() {
725 call_user_func(
726 'add_submenu_page',
727 $this->menu_args['parent_slug'],
728 $this->menu_args['page_title'],
729 $this->menu_args['menu_title'],
730 $this->menu_args['capability'],
731 $this->menu_args['menu_slug'],
732 [ $this, 'menu_output' ],
733 $this->menu_args['position']
734 );
735 }
736
737 /**
738 * Add submenu page
739 */
740 private function create_options_page() {
741 call_user_func(
742 'add_options_page',
743 $this->menu_args['page_title'],
744 $this->menu_args['menu_title'],
745 $this->menu_args['capability'],
746 $this->menu_args['menu_slug'],
747 [ $this, 'menu_output' ],
748 $this->menu_args['position']
749 );
750 }
751
752 /**
753 * Schedule daily sicense checker event
754 */
755 public function schedule_cron_event() {
756 if ( ! wp_next_scheduled( $this->schedule_hook ) ) {
757 wp_schedule_event( time(), 'daily', $this->schedule_hook );
758
759 wp_schedule_single_event( time() + 20, $this->schedule_hook );
760 }
761 }
762
763 /**
764 * Clear any scheduled hook
765 */
766 public function clear_scheduler() {
767 wp_clear_scheduled_hook( $this->schedule_hook );
768 }
769
770 /**
771 * Enable/Disable schedule
772 */
773 private function run_schedule() {
774 switch ( $this->client->type ) {
775 case 'plugin':
776 register_activation_hook( $this->client->file, [ $this, 'schedule_cron_event' ] );
777 register_deactivation_hook( $this->client->file, [ $this, 'clear_scheduler' ] );
778 break;
779
780 case 'theme':
781 add_action( 'after_switch_theme', [ $this, 'schedule_cron_event' ] );
782 add_action( 'switch_theme', [ $this, 'clear_scheduler' ] );
783 break;
784 }
785 }
786
787 /**
788 * Get input license key
789 *
790 * @return $license
791 */
792 private function get_input_license_value( $action, $license ) {
793 if ( 'active' === $action ) {
794 return isset( $license['key'] ) ? $license['key'] : '';
795 }
796
797 if ( 'deactive' === $action ) {
798 $key_length = strlen( $license['key'] );
799
800 return str_pad(
801 substr( $license['key'], 0, $key_length / 2 ),
802 $key_length,
803 '*'
804 );
805 }
806
807 return '';
808 }
809 }
810