PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 3.19.4
GiveWP – Donation Plugin and Fundraising Platform v3.19.4
4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 2.32.0 2.33.0 2.33.1 2.33.2 2.33.3 2.33.4 2.33.5 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.5.0 2.5.1 2.5.10 2.5.11 2.5.12 2.5.13 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 2.6.2 2.6.3 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.8.0 2.8.1 2.9.0 2.9.1 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.10.0 3.11.0 3.12.0 3.12.1 3.12.2 3.12.3 3.13.0 3.14.0 3.14.1 3.14.2 3.15.0 3.15.1 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.16.5 3.17.0 3.17.1 3.17.2 3.18.0 3.19.0 3.19.1 3.19.2 3.19.3 3.19.4 3.2.0 3.2.1 3.2.2 3.20.0 3.21.0 3.21.1 3.22.0 3.22.1 3.22.2 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 3.6.0 3.6.1 3.6.2 3.7.0 3.8.0 3.9.0 4.0.0 4.1.0 4.1.1 4.10.0 4.10.1 4.11.0 4.12.0 4.13.0 4.13.1 4.13.2 4.14.0 4.14.1 4.14.2 4.14.3 4.14.4 4.14.5 4.14.6 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.1 4.7.0 4.7.1 4.8.0 4.8.1 4.9.0 trunk 1.9.0 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.2 2.11.3 2.12.0 2.12.1 2.12.2 2.12.3 2.13.0 2.13.1 2.13.2 2.13.3 2.13.4 2.14.0 2.15.0 2.16.0 2.16.1 2.17.0 2.17.1 2.17.3 2.18.0 2.18.1 2.19.1 2.19.2 2.19.3 2.19.4 2.19.5 2.19.6 2.19.7 2.19.8 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.20.0 2.20.1 2.20.2 2.21.0 2.21.1 2.21.2 2.21.3 2.21.4 2.22.0 2.22.1 2.22.2 2.22.3 2.23.0 2.23.1 2.23.2 2.24.0 2.24.1 2.24.2 2.25.0 2.25.1 2.25.2 2.25.3 2.26.0 2.27.0 2.27.1 2.27.2 2.27.3 2.28.0 2.29.0 2.29.1 2.29.2
give / includes / class-give-license-handler.php
give / includes Last commit date
admin 1 year ago api 3 years ago database 2 years ago deprecated 3 years ago donors 1 year ago emails 3 years ago forms 1 year ago frontend 6 years ago gateways 1 year ago libraries 2 years ago payments 1 year ago actions.php 5 years ago ajax-functions.php 2 years ago class-give-async-process.php 1 year ago class-give-background-updater.php 2 years ago class-give-cache-setting.php 2 years ago class-give-cache.php 3 years ago class-give-cli-commands.php 3 years ago class-give-comment.php 6 years ago class-give-cron.php 6 years ago class-give-donate-form.php 1 year ago class-give-donor.php 2 years ago class-give-email-access.php 5 years ago class-give-license-handler.php 1 year ago class-give-logging.php 5 years ago class-give-readme-parser.php 4 years ago class-give-roles.php 6 years ago class-give-scripts.php 2 years ago class-give-session.php 5 years ago class-give-stats.php 6 years ago class-give-template-loader.php 6 years ago class-give-tooltips.php 6 years ago class-give-translation.php 4 years ago class-notices.php 2 years ago country-functions.php 1 year ago currencies-list.php 3 years ago currency-functions.php 3 years ago error-tracking.php 6 years ago filters.php 3 years ago formatting.php 1 year ago install.php 2 years ago login-register.php 2 years ago misc-functions.php 1 year ago plugin-compatibility.php 6 years ago post-types.php 1 year ago price-functions.php 6 years ago process-donation.php 1 year ago setting-functions.php 6 years ago shortcodes.php 1 year ago template-functions.php 4 years ago user-functions.php 3 years ago
class-give-license-handler.php
996 lines
1 <?php
2 /**
3 * Give License handler
4 *
5 * @package Give
6 * @subpackage Admin/License
7 * @copyright Copyright (c) 2016, GiveWP
8 * @license https://opensource.org/licenses/gpl-license GNU Public License
9 * @since 1.0
10 */
11
12 // Exit if accessed directly.
13 use Give\Log\Log;
14
15 if ( ! defined('ABSPATH') ) {
16 exit;
17 }
18
19 if ( ! class_exists('Give_License') ) :
20
21 /**
22 * Give_License Class
23 *
24 * This class simplifies the process of adding license information
25 * to new Give add-ons.
26 *
27 * @since 1.0
28 */
29 class Give_License
30 {
31
32 /**
33 * File
34 *
35 * @access private
36 * @since 1.0
37 *
38 * @var string
39 */
40 private $file;
41
42 /**
43 * License
44 *
45 * @access private
46 * @since 1.0
47 *
48 * @var string
49 */
50 private $license;
51
52 /**
53 * Item name
54 *
55 * @access private
56 * @since 1.0
57 *
58 * @var string
59 */
60 private $item_name;
61
62 /**
63 * Item ID
64 *
65 * @access private
66 * @since 2.2.4
67 *
68 * @var int
69 */
70 private $item_id;
71
72 /**
73 * License Information object.
74 *
75 * @access private
76 * @since 1.7
77 *
78 * @var object
79 */
80 private $license_data;
81
82 /**
83 * Item shortname
84 *
85 * @access private
86 * @since 1.0
87 *
88 * @var string
89 */
90 private $item_shortname;
91
92 /**
93 * Version
94 *
95 * @access private
96 * @since 1.0
97 *
98 * @var string
99 */
100 private $version;
101
102 /**
103 * Author
104 *
105 * @access private
106 * @since 1.0
107 *
108 * @var string
109 */
110 private $author;
111
112 /**
113 * Plugin directory name
114 *
115 * @access private
116 * @since 2.5.0
117 *
118 * @var string
119 */
120 private $plugin_dirname;
121
122 /**
123 * Website URL
124 *
125 * @access private
126 * @since 1.0
127 *
128 * @var string
129 */
130 private static $site_url = 'https://givewp.com/';
131
132 /**
133 * API URL
134 *
135 * @access private
136 * @since 1.0
137 *
138 * @var string
139 */
140 private static $api_url = 'https://givewp.com/edd-sl-api/';
141
142 /**
143 * array of licensed addons
144 *
145 * @since 2.1.4
146 * @access private
147 *
148 * @var array
149 */
150 private static $licensed_addons = [];
151
152 /**
153 * Account URL
154 *
155 * @access private
156 * @since 1.7
157 *
158 * @var null|string
159 */
160 private static $account_url = 'http://docs.givewp.com/settings-account';
161
162 /**
163 * Downloads URL
164 *
165 * @access private
166 * @since 2.5.0
167 *
168 * @var null|string
169 */
170 private static $downloads_url = 'http://docs.givewp.com/settings-downloads';
171
172 /**
173 * Checkout URL
174 *
175 * @access private
176 * @since 1.7
177 *
178 * @var null|string
179 */
180 private static $checkout_url = 'https://givewp.com/checkout/';
181
182 /**
183 * Class Constructor
184 *
185 * Set up the Give License Class.
186 *
187 * @access public
188 *
189 * @param string $_file
190 * @param string $_item_name
191 * @param string $_version
192 * @param string $_author
193 * @param string $_optname
194 * @param string $_api_url
195 * @param string $_checkout_url
196 * @param string $_account_url
197 * @param int $_item_id
198 *
199 * @since 3.17.2 removed unused auto_updater_obj property assignment
200 * @since 1.0
201 */
202 public function __construct(
203 $_file,
204 $_item_name,
205 $_version,
206 $_author,
207 $_optname = null,
208 $_api_url = null,
209 $_checkout_url = null,
210 $_account_url = null,
211 $_item_id = null
212 ) {
213
214 // Only load in wp-admin.
215 if ( ! is_admin() ) {
216 return;
217 }
218
219 if ( is_numeric( $_item_id ) ) {
220 $this->item_id = absint( $_item_id );
221 }
222
223 $this->file = $_file;
224 $this->item_name = $_item_name;
225 $this->plugin_dirname = dirname( plugin_basename( $this->file ) );
226 $this->item_shortname = self::get_short_name( $this->item_name );
227 $this->license_data = self::get_license_by_plugin_dirname( $this->plugin_dirname );
228 $this->version = $_version;
229 $this->license = ! empty( $this->license_data['license_key'] ) ? $this->license_data['license_key'] : '';
230 $this->author = $_author;
231 self::$api_url = is_null( $_api_url ) ? self::$api_url : $_api_url;
232 self::$checkout_url = is_null( $_checkout_url ) ? self::$checkout_url : $_checkout_url;
233 self::$account_url = is_null( $_account_url ) ? self::$account_url : $_account_url;
234
235 // Add plugin to registered licenses list.
236 array_push( self::$licensed_addons, plugin_basename( $this->file ) );
237 }
238
239
240 /**
241 * Get plugin shortname
242 *
243 * @param $plugin_name
244 *
245 * @return string
246 * @since 2.1.0
247 * @access public
248 */
249 public static function get_short_name( $plugin_name ) {
250 $plugin_name = trim( str_replace( 'Give - ', '', $plugin_name ) );
251 $plugin_name = 'give_' . preg_replace( '/[^a-zA-Z0-9_\s]/', '', str_replace( ' ', '_', strtolower( $plugin_name ) ) );
252
253 return $plugin_name;
254 }
255
256 /**
257 * Activate License
258 *
259 * Activate the license key.
260 *
261 * @access public
262 * @return void
263 * @since 1.0
264 */
265 public function activate_license() {
266 }
267
268 /**
269 * Deactivate License
270 *
271 * Deactivate the license key.
272 *
273 * @access public
274 * @return void
275 * @since 1.0
276 */
277 public function deactivate_license() {
278 }
279
280
281 /**
282 * Get license information.
283 *
284 * @param string $edd_action
285 * @param bool $response_in_array
286 *
287 * @return mixed
288 * @deprecated 2.5.0 Use self::request_license_api instead.
289 *
290 * @since 1.8.9
291 * @access public
292 */
293 public function get_license_info($edd_action = '', $response_in_array = false)
294 {
295 if ( empty($edd_action) ) {
296 return false;
297 }
298
299 give_doing_it_wrong(__FUNCTION__, 'Use self::request_license_api instead from GiveWP 2.5.0');
300
301 // Data to send to the API.
302 $api_params = [
303 'edd_action' => $edd_action, // never change from "edd_" to "give_"!
304 'license' => $this->license,
305 'item_name' => urlencode($this->item_name),
306 ];
307
308 return self::request_license_api($api_params, $response_in_array);
309 }
310
311 /**
312 * Return licensed addons info
313 *
314 * Note: note only for internal logic
315 *
316 * @since 2.1.4
317 * @return array
318 */
319 static function get_licensed_addons()
320 {
321 return self::$licensed_addons;
322 }
323
324
325 /**
326 * Check if license key attached to subscription
327 *
328 * @since 2.5.0
329 *
330 * @param string $license_key
331 *
332 * @return array
333 */
334 static function is_subscription($license_key = '')
335 {
336 // Check if current license is part of subscription or not.
337 $subscriptions = get_option('give_subscriptions');
338 $subscription = [];
339
340 if ( $subscriptions ) {
341 foreach ($subscriptions as $subs) {
342 if ( in_array($license_key, $subs['licenses']) ) {
343 $subscription = $subs;
344 break;
345 }
346 }
347 }
348
349 return $subscription;
350 }
351
352 /**
353 * Get license information.
354 *
355 * @since 1.8.9
356 * @since 2.18.0 log failed license api request information
357 *
358 * @param bool $response_in_array
359 *
360 * @param array $api_params
361 *
362 * @return array|WP_Error
363 */
364 public static function request_license_api($api_params = [], $response_in_array = false)
365 {
366 // Bailout.
367 if ( empty($api_params['edd_action']) ) {
368 return new WP_Error('give-invalid-edd-action', __('Valid edd_action not defined', 'give'));
369 }
370
371 // Data to send to the API.
372 $default_api_params = [
373 // 'edd_action' => $edd_action, never change from "edd_" to "give_"!
374 // 'license' => $this->license,
375 // 'item_name' => urlencode( $this->item_name ),
376 'url' => home_url(),
377 ];
378
379 $api_params = wp_parse_args($api_params, $default_api_params);
380
381 // Call the API.
382 $response = wp_remote_post(
383 self::$api_url,
384 apply_filters(
385 'give_request_license_api_args',
386 [
387 'timeout' => 15,
388 'sslverify' => false,
389 'body' => $api_params,
390 ]
391 )
392 );
393
394 $statusCode = wp_remote_retrieve_response_code($response);
395 $body = json_decode(wp_remote_retrieve_body($response), $response_in_array);
396
397 if ( 200 !== $statusCode ) {
398 Log::http(
399 'License Api request failed',
400 [
401 'category' => 'License',
402 'api url' => self::$api_url,
403 'request' => $api_params,
404 'status code' => $statusCode,
405 'response' => $response
406 ]
407 );
408 }
409
410 // Make sure there are no errors.
411 if ( is_wp_error($response) ) {
412 return $response;
413 }
414
415 return $body;
416 }
417
418 /**
419 * Get license by plugin dirname
420 *
421 * @param string $plugin_dirname
422 *
423 * @return array
424 *
425 * @since 2.5.0
426 * @access public
427 */
428 public static function get_license_by_plugin_dirname( $plugin_dirname ) {
429 $license = [];
430 $give_licenses = get_option( 'give_licenses', [] );
431
432 if ( ! empty( $give_licenses ) ) {
433 foreach ( $give_licenses as $give_license ) {
434
435 // Logic to match all access pass license to add-on.
436 $compares = $give_license['is_all_access_pass']
437 ? $give_license['download']
438
439 // Prevent PHP notice if somehow automatic update does not run properly.
440 // Because plugin_slug will only define in updated license rest api response.
441 : [ [ 'plugin_slug' => ! empty( $give_license['plugin_slug'] ) ? $give_license['plugin_slug'] : '' ] ];
442
443 foreach ( $compares as $compare ) {
444 if ( ! empty( $compare['plugin_slug'] ) && $plugin_dirname === $compare['plugin_slug'] ) {
445 $license = $give_license;
446 break;
447 }
448 }
449 }
450 }
451
452 return $license;
453 }
454
455
456 /**
457 * Get checkout url
458 *
459 * @return string|null
460 * @since 2.5.0
461 */
462 public static function get_checkout_url() {
463 return self::$checkout_url;
464 }
465
466 /**
467 * Get account url
468 *
469 * @return string|null
470 * @since 2.5.0
471 */
472 public static function get_account_url() {
473 return self::$account_url;
474 }
475
476 /**
477 * Get downloads url
478 *
479 * @return string|null
480 * @since 2.5.0
481 */
482 public static function get_downloads_url() {
483 return self::$downloads_url;
484 }
485
486 /**
487 * Get account url
488 *
489 * @return string|null
490 * @since 2.5.0
491 */
492 public static function get_website_url() {
493 return self::$site_url;
494 }
495
496
497 /**
498 * Get plugin information by id.
499 * Note: only for internal use
500 *
501 * @param string $plugin_slug
502 *
503 * @return array
504 * @since 2.5.0
505 */
506 public static function get_plugin_by_slug( $plugin_slug ) {
507 $give_plugins = give_get_plugins();
508 $matching_list = wp_list_pluck( $give_plugins, 'Dir', 'Path' );
509 $is_match_found = array_search( $plugin_slug, $matching_list, true );
510
511 return $is_match_found ? $give_plugins[ $is_match_found ] : [];
512 }
513
514 /**
515 * Get plugin information by id.
516 * Note: only for internal use
517 *
518 * @param string $plugin_slug
519 *
520 * @return string
521 * @since 2.5.0
522 */
523 public static function build_plugin_name_from_slug( $plugin_slug ) {
524 $plugin_name = str_replace( [ '-', 'give ' ], [ ' ', 'Give - ' ], $plugin_slug );
525
526 return ucwords( $plugin_name );
527 }
528
529 /**
530 * Render license section
531 *
532 * @return string
533 * @since 2.5.0
534 */
535 public static function render_licenses_list() {
536 $give_plugins = give_get_plugins( [ 'only_premium_add_ons' => true ] );
537 $give_licenses = get_option( 'give_licenses', [] );
538 $licenses_without_addon = $give_licenses;
539
540 // Get all access pass licenses
541 $all_access_pass_licenses = [];
542 $all_access_pass_addon_list = [];
543 foreach ( $give_licenses as $key => $give_license ) {
544 if ( $give_license['is_all_access_pass'] ) {
545 $all_access_pass_licenses[ $key ] = $give_license;
546
547 unset( $licenses_without_addon[ $key ] );
548
549 foreach ( $give_license['download'] as $download ) {
550 $all_access_pass_addon_list[] = $download['plugin_slug'];
551 }
552 }
553 }
554
555 $html = [
556 'unlicensed' => '',
557 'licensed' => '',
558 'licenses_without_addon' => '',
559 'all_access_licensed' => '',
560 ];
561
562 if ( ! empty( $give_plugins ) ) {
563 foreach ( $give_plugins as $give_plugin ) {
564 if ( in_array( $give_plugin['Dir'], $all_access_pass_addon_list ) ) {
565 continue;
566 }
567
568 $addon_license = self::get_license_by_plugin_dirname( $give_plugin['Dir'] );
569 $html_arr_key = 'unlicensed';
570
571 if ( $addon_license ) {
572 $html_arr_key = 'licensed';
573 unset( $licenses_without_addon[ $addon_license['license_key'] ] );
574 }
575
576 $html[ "{$html_arr_key}" ] .= self::html_by_plugin( $give_plugin );
577 }
578 }
579
580 if ( ! empty( $all_access_pass_licenses ) ) {
581 foreach ( $all_access_pass_licenses as $key => $all_access_pass_license ) {
582 $html['all_access_licensed'] .= self::html_by_license( $all_access_pass_license );
583 }
584 }
585
586 if ( ! empty( $licenses_without_addon ) ) {
587 foreach ( $licenses_without_addon as $key => $license ) {
588 if ( in_array( $license['plugin_slug'], $all_access_pass_addon_list ) ) {
589 continue;
590 }
591 $html['licenses_without_addon'] .= self::html_by_license( $license );
592 }
593 }
594
595 ksort( $html );
596
597 // After sorting order will be all_access_licensed -> licensed -> unlicensed
598
599 return implode( '', $html );
600 }
601
602 /**
603 * Get add-on item html
604 * Note: only for internal use
605 *
606 * @param $plugin
607 *
608 * @return string
609 * @since 2.5.0
610 */
611 public static function html_by_plugin( $plugin ) {
612 // Bailout.
613 if ( empty( $plugin ) ) {
614 return '';
615 }
616
617 ob_start();
618 $license = self::get_license_by_plugin_dirname( $plugin['Dir'] );
619
620 $default_plugin = [
621 'ChangeLogSlug' => $plugin['Dir'],
622 'DownloadURL' => '',
623 ];
624
625 if ( false !== strpos( $default_plugin['ChangeLogSlug'], '-gateway' ) ) {
626 // We found that each gateway addon does not have `-gateway` in changelog file slug
627 $default_plugin['ChangeLogSlug'] = str_replace( '-gateway', '', $default_plugin['ChangeLogSlug'] );
628 }
629
630 if ( $license ) {
631 $license['renew_url'] = self::$checkout_url . "?edd_license_key={$license['license_key']}";
632 $default_plugin['ChangeLogSlug'] = $license['readme'];
633 $default_plugin['DownloadURL'] = $license['download'];
634 }
635
636 $plugin['License'] = $license = wp_parse_args(
637 $license,
638 [
639 'item_name' => str_replace( 'give-', '', $plugin['Dir'] ),
640 'purchase_link' => $plugin['PluginURI'],
641 ]
642 );
643
644 $plugin = wp_parse_args( $plugin, $default_plugin );
645 ?>
646 <div class="give-addon-wrap">
647 <div class="give-addon-inner">
648 <?php echo self::html_license_row( $license, $plugin ); ?>
649 <?php echo self::html_plugin_row( $plugin ); ?>
650 </div>
651 </div>
652 <?php
653
654 return ob_get_clean();
655 }
656
657 /**
658 * Get add-on item html
659 * Note: only for internal use
660 *
661 * @param array $license
662 *
663 * @return string
664 * @since 2.5.0
665 */
666 private static function html_by_license( $license ) {
667 ob_start();
668
669 $license['renew_url'] = self::$checkout_url . "?edd_license_key={$license['license_key']}";
670 ?>
671 <div class="give-addon-wrap">
672 <div class="give-addon-inner">
673 <?php
674 echo self::html_license_row( $license );
675
676 $addons = $license['download'];
677
678 if ( empty( $license['is_all_access_pass'] ) ) {
679 $addons = [ $license ];
680 }
681
682 foreach ( $addons as $addon ) {
683 $default_plugin = [
684 // In single license key we will get item_name instead of name.
685 'Name' => ! empty( $addon['item_name'] ) ? $addon['item_name'] : $addon['name'],
686
687 'ChangeLogSlug' => $addon['readme'],
688 'Version' => $addon['current_version'],
689 'Status' => 'not installed',
690
691 // In single license key we will get download instead of file.
692 'DownloadURL' => ! empty( $addon['download'] ) ? $addon['download'] : $addon['file'],
693
694 ];
695
696 $plugin = wp_parse_args(
697 self::get_plugin_by_slug( $addon['plugin_slug'] ),
698 $default_plugin
699 );
700
701 $plugin['Name'] = false !== strpos( $plugin['Name'], 'Give' )
702 ? $plugin['Name']
703 : self::build_plugin_name_from_slug( $addon['plugin_slug'] );
704
705 $plugin['License'] = $license;
706
707 echo self::html_plugin_row( $plugin );
708 }
709 ?>
710 </div>
711 </div>
712 <?php
713
714 return ob_get_clean();
715 }
716
717
718 /**
719 * license row html
720 *
721 * @param array $license
722 * @param array $plugin
723 *
724 * @return string
725 * @since 2.5.0
726 */
727 private static function html_license_row( $license, $plugin = [] ) {
728 ob_start();
729
730 $is_license = $license && ! empty( $license['license_key'] );
731 $license_key = $is_license ? $license['license_key'] : '';
732 $license_is_inactive = $license_key && ! in_array( $license['license'], [ 'valid', 'expired' ] );
733 $expires_timestamp = $is_license ? strtotime( $license['expires'] ) : '';
734 $is_license_expired = $is_license && ( 'expired' === $license['license'] || $expires_timestamp < time() );
735 $addon_dir = ! empty( $plugin['Dir'] ) ? $plugin['Dir'] : ( ! empty( $license['plugin_slug'] ) ? $license['plugin_slug'] : '' );
736 ?>
737 <div class="give-license-row give-clearfix">
738 <div class="give-license-notice-container"></div>
739 <div class="give-license-top give-clearfix">
740
741 <div class="give-license-top-column give-license-key-field-wrap">
742
743 <div class="give-license__key<?php echo $license_key ? ' give-has-license-key' : ''; ?>">
744 <?php $value = $license_key ? give_hide_char( $license['license_key'], 5 ) : ''; ?>
745 <label for="give-license-addon-key-field" class="give-license-top-header"><?php _e( 'License Key', 'give' ); ?></label>
746 <input id="give-license-addon-key-field" type="text" autocomplete="off" value="<?php echo $value; ?>"<?php echo $value ? ' readonly' : ''; ?>>
747 <?php if ( ! $license_key ) : ?>
748 <button class="give-button__license-activate button-primary" data-addon="<?php echo $addon_dir; ?>">
749 <?php _e( 'Activate', 'give' ); ?>
750 </button>
751 <?php elseif ( $license_is_inactive ) : ?>
752 <button class="give-button__license-reactivate button-primary" data-addon="<?php echo $addon_dir; ?>" data-license="<?php echo $license['license_key']; ?>">
753 <?php _e( 'Reactivate', 'give' ); ?>
754 </button>
755 <?php else : ?>
756
757 <?php
758 echo sprintf(
759 '<button class="give-license__deactivate button button-secondary" data-license-key="%2$s" data-item-name="%3$s" data-plugin-dirname="%5$s" data-nonce="%4$s">%1$s</button>',
760 __( 'Deactivate', 'give' ),
761 $license['license_key'],
762 $license['item_name'],
763 wp_create_nonce( "give-deactivate-license-{$license['item_name']}" ),
764 ! empty( $license['plugin_slug'] ) ? $license['plugin_slug'] : ''
765 );
766 ?>
767
768 <?php endif; ?>
769
770 <div class="give-license__status">
771 <?php
772 echo $license_key && ! $license_is_inactive
773 ? sprintf(
774 '<span class="dashicons dashicons-%2$s"></span>&nbsp;%1$s',
775 $is_license_expired
776 ? __( 'License is expired. Please activate your license key.', 'give' )
777 : __( 'License is active and you are receiving updates and support.', 'give' ),
778 $is_license_expired
779 ? 'no'
780 : 'yes'
781 )
782 : sprintf(
783 '<span class="dashicons dashicons-no"></span> %1$s %2$s',
784 __( 'License is inactive.', 'give' ),
785 $license_is_inactive
786 ? sprintf(
787 __( 'Please <a href="%1$s" target="_blank">Visit your dashboard</a> to check this license details and activate this license to receive updates and support.', 'give' ),
788 self::get_account_url()
789 )
790 : __( 'Please activate your license key.', 'give' )
791 );
792 ?>
793 </div>
794 </div>
795 </div>
796
797 <div class="give-license-top-column give-license-info-field-wrap">
798 <h3 class="give-license-top-header"><?php _e( 'License Information', 'give' ); ?></h3>
799 <?php
800 // @todo: handle all license status;
801 if ( $license_key ) :
802 ?>
803
804 <?php if ( $license_key ) : ?>
805 <?php
806 echo sprintf(
807 '<p class="give-license-renewal-date"><span class="dashicons dashicons-calendar-alt"></span> <strong>%1$s</strong> %2$s</p>',
808 $is_license_expired ? __( 'Expired:', 'give' ) : __( 'Renews:', 'give' ),
809 date( give_date_format(), $expires_timestamp )
810 );
811 ?>
812 <?php endif; ?>
813
814 <?php
815 if ( $is_license_expired ) {
816 // @todo: need to test renew license link
817 echo sprintf(
818 '<a href="%1$s" target="_blank">%2$s</a>',
819 $license['renew_url'],
820 __( 'Renew to manage sites', 'give' )
821 );
822 } elseif ( $license_key ) {
823 if ( ! $license['activations_left'] ) {
824 echo sprintf(
825 '<span class="give-license-activations-left">%1$s</span>',
826 __( 'No activations remaining', 'give' )
827 );
828 } else {
829 echo sprintf(
830 '<span class="give-license-activations-left"><span class="give-license-activations-remaining-icon wp-ui-highlight">%1$s</span> %2$s</span>',
831 $license['activations_left'],
832 _n( 'Activation Remaining', 'Activations Remaining', $license['activations_left'], 'give' )
833 );
834 }
835 }
836 ?>
837 <?php else : ?>
838
839 <p class="give-field-description"><?php _e( 'This is an unlicensed add-on and is not receiving updates or support. Please activate your license key to fix the issue.', 'give' ); ?></p>
840
841 <?php endif; ?>
842 </div>
843
844 <div class="give-license-top-column">
845 <h3 class="give-license-top-header"><?php _e( 'License Actions', 'give' ); ?></h3>
846
847 <?php
848 // Purchase license link.
849 if ( ! $license_key ) :
850 ?>
851 <?php
852 echo sprintf(
853 '<a class="give-button button-secondary" href="%1$s" target="_blank">%2$s</a>',
854 $license['purchase_link'],
855 __( 'Purchase License', 'give' )
856 );
857 ?>
858 <?php endif; ?>
859
860 <?php
861 // Manage license link on GiveWP.com
862 if ( ! $is_license_expired && $license_key ) {
863 echo sprintf(
864 '<a href="%1$spurchase-history/?license_id=%2$s&action=manage_licenses&payment_id=%3$s" target="_blank" class="give-license-action-link">%4$s</a>',
865 trailingslashit( self::get_website_url() ),
866 $license['license_id'],
867 $license['payment_id'],
868 __( 'Manage License', 'give' )
869 );
870 echo sprintf(
871 '<a href="%1$spriority-support/" target="_blank" class="give-license-action-link">%2$s</a>',
872 trailingslashit( self::get_website_url() ),
873 __( 'Access Support', 'give' )
874 );
875 }
876 ?>
877
878 </div>
879 </div>
880 </div>
881 <?php
882 return ob_get_clean();
883 }
884
885
886 /**
887 * Plugin row html
888 *
889 * @param array $plugin
890 *
891 * @return string
892 * @since 2.5.0
893 */
894 public static function html_plugin_row( $plugin ) {
895 // Bailout.
896 if ( ! $plugin ) {
897 return '';
898 }
899
900 $is_license = $plugin['License'] && ! empty( $plugin['License']['license_key'] );
901 $expires_timestamp = $is_license ? strtotime( $plugin['License']['expires'] ) : '';
902 $is_license_expired = $is_license && ( 'expired' === $plugin['License']['license'] || $expires_timestamp < time() );
903 ob_start();
904 ?>
905 <div class="give-addon-info-wrap give-clearfix">
906
907 <div class="give-addon-info-left">
908 <span class="give-addon-name">
909 <?php echo $plugin['Name']; ?>
910 </span>
911 <span class="give-addon-version">
912 <?php echo sprintf( '%1$s %2$s', __( 'Version', 'give' ), $plugin['Version'] ); ?>
913 </span>
914 </div>
915
916 <div class="give-addon-info-right">
917 <?php
918 echo sprintf(
919 '<a href="%1$s" class="give-ajax-modal give-addon-view-changelog" title="%3$s">%2$s</a>',
920 give_modal_ajax_url(
921 [
922 'url' => filter_var( $plugin['ChangeLogSlug'], FILTER_VALIDATE_URL )
923 ? urldecode_deep( $plugin['ChangeLogSlug'] )
924 : urlencode_deep( give_get_addon_readme_url( $plugin['ChangeLogSlug'] ) ),
925 'show_changelog' => 1,
926 ]
927 ),
928 __( 'View Changelog', 'give' ),
929 __( 'Changelog of', 'give' ) . " {$plugin['Name']}"
930 );
931 ?>
932
933 <?php
934 // Activation status.
935 if ( in_array( $plugin['Status'], [ 'active', 'inactive' ] ) ) {
936 echo sprintf(
937 '<span class="give-addon-activation-status give-addon-activation-status__%1$s">%1$s</span>',
938 'active' === $plugin['Status'] ? __( 'activated', 'give' ) : __( 'installed', 'give' )
939 );
940 }
941
942 printf(
943 '<%3$s class="give-button button button-secondary button-small" href="%1$s"%4$s><span class="dashicons dashicons-download"></span>%2$s</%3$s>',
944 $plugin['DownloadURL'],
945 __( 'Download', 'give' ),
946 $is_license_expired || ! $plugin['DownloadURL'] ? 'button' : 'a',
947 $is_license_expired || ! $plugin['DownloadURL'] ? ' disabled' : ''
948 );
949 ?>
950 </div>
951 </div>
952 <?php
953
954 return ob_get_clean();
955 }
956
957
958 /**
959 * Get refresh license status
960 *
961 * @return mixed|void
962 * @since 2.5.0
963 */
964 public static function refresh_license_status() {
965 return get_option(
966 'give_licenses_refreshed_last_checked',
967 [
968 'compare' => date( 'Ymd' ),
969 'time' => time(),
970 'count' => 0,
971 ]
972 );
973 }
974
975 /**
976 * Get all download slugs from all access pass key.
977 * Note: only for internal use and will be refactored in the future.
978 *
979 * @param array $license All access pass license data
980 *
981 * @return string[]
982 * @since 2.6.3
983 */
984 public static function getAddonSlugsFromAllAccessPassLicense( $license ) {
985 $result = [];
986
987 foreach ( $license['download'] as $download ) {
988 $result[] = $download['plugin_slug'];
989 }
990
991 return $result;
992 }
993 }
994
995 endif; // end class_exists check.
996