PluginProbe ʕ •ᴥ•ʔ
WP All Export – Drag & Drop Export to Any Custom CSV, XML & Excel / trunk
WP All Export – Drag & Drop Export to Any Custom CSV, XML & Excel vtrunk
trunk 0.9.0 0.9.1 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.2.0 1.2.1 1.2.10 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.10 1.4.11 1.4.12 1.4.13 1.4.14 1.4.15 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.5.0
wp-all-export / src / App / Service / License / LicenseActivator.php
wp-all-export / src / App / Service / License Last commit date
LicenseActivator.php 1 year ago
LicenseActivator.php
94 lines
1 <?php
2
3 namespace Wpae\App\Service\License;
4
5
6 use \PMXE_Plugin;
7
8 class LicenseActivator
9 {
10 const CONTEXT_PMXE = 1;
11 const CONTEXT_SCHEDULING = 2;
12
13 public function activateLicense($productName, $context = self::CONTEXT_PMXE)
14 {
15 if($context == self::CONTEXT_PMXE) {
16 $licenseField = 'license';
17 $licenseStatusField = 'license_status';
18 } else {
19 $licenseField = 'scheduling_license';
20 $licenseStatusField = 'scheduling_license_status';
21 }
22
23 $options = PMXE_Plugin::getInstance()->getOption();
24
25 if ($productName !== false) {
26 // data to send in our API request
27 $api_params = array(
28 'edd_action' => 'activate_license',
29 'license' => PMXE_Plugin::decode($options[$licenseField]),
30 'item_name' => urlencode($productName), // the name of our product in EDD
31 'url' => home_url()
32 );
33
34 // Call the custom API.
35 $response = wp_remote_get(esc_url_raw(add_query_arg($api_params, $options['info_api_url'])), array('timeout' => 15, 'sslverify' => false));
36
37 // make sure the response came back okay
38 if (is_wp_error($response))
39 return false;
40
41 // decode the license data
42 $license_data = json_decode(wp_remote_retrieve_body($response));
43 if('scheduling_license' == $licenseField){
44 update_option('wpai_wpae_scheduling_license_site_limit', $license_data->license_limit ?? 0);
45 }
46
47 // $license_data->license will be either "active" or "inactive"
48
49 $options[$licenseStatusField] = $license_data->license;
50
51 PMXE_Plugin::getInstance()->updateOption($options);
52 }
53 }
54
55 /**
56 * @param $productName
57 * @param $options
58 * @param $context
59 * @return bool
60 */
61 public function checkLicense($productName, $options, $context)
62 {
63 if($context == self::CONTEXT_PMXE) {
64 $licenseField = 'license';
65 } else {
66 $licenseField = 'scheduling_license';
67 }
68
69 if (!empty($options[$licenseField])) {
70
71 if ($productName !== false) {
72
73 $api_params = array(
74 'edd_action' => 'check_license',
75 'license' => PMXE_Plugin::decode($options[$licenseField]),
76 'item_name' => urlencode($productName)
77 );
78
79 // Call the custom API.
80 $response = wp_remote_get(esc_url_raw(add_query_arg($api_params, $options['info_api_url'])), array('timeout' => 15, 'sslverify' => false));
81
82 if (is_wp_error($response))
83 return false;
84
85 $license_data = json_decode(wp_remote_retrieve_body($response));
86
87 return $license_data->license;
88
89 }
90 }
91
92 return false;
93 }
94 }