PluginProbe ʕ •ᴥ•ʔ
WP All Export – Drag & Drop Export to Any Custom CSV, XML & Excel / 1.2.10
WP All Export – Drag & Drop Export to Any Custom CSV, XML & Excel v1.2.10
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 4 years ago
LicenseActivator.php
91 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(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
44 // $license_data->license will be either "active" or "inactive"
45
46 $options[$licenseStatusField] = $license_data->license;
47
48 PMXE_Plugin::getInstance()->updateOption($options);
49 }
50 }
51
52 /**
53 * @param $productName
54 * @param $options
55 * @param $context
56 * @return bool
57 */
58 public function checkLicense($productName, $options, $context)
59 {
60 if($context == self::CONTEXT_PMXE) {
61 $licenseField = 'license';
62 } else {
63 $licenseField = 'scheduling_license';
64 }
65
66 if (!empty($options[$licenseField])) {
67
68 if ($productName !== false) {
69
70 $api_params = array(
71 'edd_action' => 'check_license',
72 'license' => PMXE_Plugin::decode($options[$licenseField]),
73 'item_name' => urlencode($productName)
74 );
75
76 // Call the custom API.
77 $response = wp_remote_get(add_query_arg($api_params, $options['info_api_url']), array('timeout' => 15, 'sslverify' => false));
78
79 if (is_wp_error($response))
80 return false;
81
82 $license_data = json_decode(wp_remote_retrieve_body($response));
83
84 return $license_data->license;
85
86 }
87 }
88
89 return false;
90 }
91 }