PluginProbe ʕ •ᴥ•ʔ
Flex Import / 2.8
Flex Import v2.8
2.9 trunk 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8
flex-import / includes / fleximp-license-functions.php
flex-import / includes Last commit date
class-template-importer.php 1 month ago flex-dashboard-post-api.php 1 month ago flex-get-api.php 1 month ago flex-get-templates-api.php 1 month ago fleximp-license-functions.php 1 month ago
fleximp-license-functions.php
229 lines
1 <?php
2 if (!defined('ABSPATH')) {
3 exit; // Exit if accessed directly.
4 }
5
6 function get_fleximp_validation_status()
7 {
8 return get_option('fleximp_validation_status', 'false');
9 }
10
11 function set_fleximp_validation_status($is_valid)
12 {
13 update_option('fleximp_validation_status', $is_valid);
14 }
15
16 function get_fleximp_suspension_status()
17 {
18 return get_option('fleximp_suspension_status', 'false');
19 }
20
21 function set_fleximp_suspension_status($is_suspended)
22 {
23 update_option('fleximp_suspension_status', $is_suspended);
24 }
25
26 function set_fleximp_key($license_key)
27 {
28 update_option('fleximp_is_premium', $license_key);
29 }
30
31 function remove_fleximp_key()
32 {
33 delete_option('fleximp_is_premium');
34 }
35
36 function get_fleximp_key()
37 {
38 return get_option('fleximp_is_premium');
39 }
40
41 // bundle
42 function get_fleximp_bundle_status()
43 {
44 return get_option('fleximp_is_bundle', 'false');
45 }
46
47 function set_fleximp_bundle_status($is_bundle)
48 {
49 update_option('fleximp_is_bundle', $is_bundle);
50 }
51
52 function remove_fleximp_bundle_status()
53 {
54 delete_option('fleximp_is_bundle');
55 }
56
57
58 function fleximp_license_admin_scripts($hook)
59 {
60
61 if ($hook == 'flex-importer_page_fleximp-license-key') {
62 wp_enqueue_style('fleximp-license-css', FLEXIMP_PLUGIN_DIR_FILE . 'assets/css/fleximp-license-style.css', [], FLEXIMP_VER);
63 }
64
65 wp_enqueue_script('fleximp-notify-js', FLEXIMP_PLUGIN_DIR_FILE . '/assets/js/jquery.notify.min.js', [], FLEXIMP_VER);
66 wp_register_script(
67 'fleximp-license-admin-script',
68 FLEXIMP_PLUGIN_DIR_FILE . 'assets/js/license_script.js',
69 [],
70 FLEXIMP_VER
71 );
72
73 $localize_script_arr = array(
74 'ajaxurl' => admin_url('admin-ajax.php'),
75 'wpnonce' => wp_create_nonce('admin_script_nonce'),
76 'redirect_url' => admin_url('admin.php?page=fleximp-template-importer'),
77 );
78
79 wp_localize_script('fleximp-license-admin-script', 'localize_script_arr', $localize_script_arr);
80 wp_enqueue_script('fleximp-license-admin-script');
81 }
82
83
84 add_action('admin_enqueue_scripts', 'fleximp_license_admin_scripts');
85
86 function license_activate_fleximp()
87 {
88
89 if (empty($_POST['fleximp_is_premium'])) {
90 wp_send_json(['status' => false, 'msg' => 'License key is required.']);
91 }
92
93 $license_key = $_POST['fleximp_is_premium'];
94 $endpoint = FLEXIMP_LICENSE_URL . 'verifyTheme';
95
96 $body = [
97 'theme_license_key' => $license_key,
98 'site_url' => site_url(),
99 'plugin_text_domain' => 'flex-import',
100 ];
101 $body = wp_json_encode($body);
102
103 $options = [
104 'body' => $body,
105 'headers' => ['Content-Type' => 'application/json'],
106 ];
107
108 $response = wp_remote_post($endpoint, $options);
109
110 if (is_wp_error($response)) {
111 remove_fleximp_key();
112 set_fleximp_validation_status('false');
113 wp_send_json(['status' => false, 'msg' => 'Something Went Wrong!']);
114 } else {
115 $response_body = json_decode(wp_remote_retrieve_body($response));
116
117 if ($response_body->is_suspended == 1) {
118 set_fleximp_suspension_status('true');
119 } else {
120 set_fleximp_suspension_status('false');
121 }
122
123 if ($response_body->status === false) {
124 remove_fleximp_key();
125 set_fleximp_validation_status('false');
126 wp_send_json(['status' => false, 'msg' => $response_body->msg]);
127 } else {
128
129 // Store bundle status (default false if not provided)
130 if (isset($response_body->is_bundle) && $response_body->is_bundle == true) {
131 set_fleximp_bundle_status('true');
132 } else {
133 set_fleximp_bundle_status('false');
134 }
135
136 set_fleximp_validation_status('true');
137 set_fleximp_key($license_key);
138
139 wp_send_json([
140 'status' => true,
141 'msg' => 'Plugin Activated Successfully!',
142 'is_bundle' => isset($response_body->is_bundle) ? $response_body->is_bundle : false
143 ]);
144 }
145
146 }
147 }
148
149 add_action('wp_ajax_license_activate_fleximp', 'license_activate_fleximp');
150
151
152 function fleximp_invalidate_license()
153 {
154 remove_fleximp_key();
155 remove_fleximp_bundle_status();
156 set_fleximp_validation_status('false');
157 }
158
159 function license_deactivate_fleximp()
160 {
161 $license_key = $_POST['fleximp_license_key'];
162
163 if ($license_key != '') {
164 $endpoint = FLEXIMP_LICENSE_URL . 'deactivateDomain';
165 $body = [
166 'theme_license_key' => $license_key,
167 'site_url' => site_url(),
168 ];
169 $body = wp_json_encode($body);
170
171 $options = [
172 'body' => $body,
173 'headers' => ['Content-Type' => 'application/json'],
174 ];
175
176 $response = wp_remote_post($endpoint, $options);
177
178 if (is_wp_error($response)) {
179 wp_send_json(['status' => false, 'msg' => 'Something Went Wrong!']);
180 } else {
181 $response_body = json_decode(wp_remote_retrieve_body($response));
182
183 if ($response_body->status === false) {
184 wp_send_json(['status' => false, 'msg' => $response_body->msg]);
185 } else {
186 fleximp_invalidate_license();
187 wp_send_json(['status' => true, 'msg' => $response_body->msg]);
188 }
189 }
190 }
191 }
192 add_action('wp_ajax_license_deactivate_fleximp', 'license_deactivate_fleximp');
193
194 function fleximp_license_expiry_notice()
195 {
196
197 $license_key = get_fleximp_key();
198 $endpoint = FLEXIMP_LICENSE_URL . 'status';
199
200 $body = [
201 'theme_license_key' => $license_key,
202 'site_url' => site_url(),
203 'plugin_text_domain' => 'flex-import',
204 ];
205 $body = wp_json_encode($body);
206
207 if ($license_key != "") {
208 $response = wp_remote_post($endpoint, [
209 'body' => $body,
210 'headers' => ['Content-Type' => 'application/json'],
211 ]);
212
213 if (!is_wp_error($response)) {
214 $response_body = json_decode(wp_remote_retrieve_body($response));
215
216 if (isset($response_body->status) && $response_body->status === false) {
217 fleximp_invalidate_license();
218 echo '<div class="notice notice-error"><p>License key is expired!</p></div>';
219 }
220
221 if (isset($response_body->is_suspended) && $response_body->is_suspended == 1) {
222 fleximp_invalidate_license();
223 set_fleximp_suspension_status('false');
224 echo '<div class="notice notice-error"><p>License key is suspended!</p></div>';
225 }
226 }
227 }
228 }
229 add_action('admin_notices', 'fleximp_license_expiry_notice');