PluginProbe ʕ •ᴥ•ʔ
Flex Import / 1.8
Flex Import v1.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
loader 1 year ago widgets 1 year ago class-template-importer.php 1 year ago flex-dashboard-post-api.php 1 year ago flex-get-api.php 1 year ago flex-get-templates-api.php 1 year ago fleximp-license-functions.php 1 year ago
fleximp-license-functions.php
190 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_is_premium', 'false');
9 }
10
11 function set_fleximp_validation_status($is_valid)
12 {
13 update_option('fleximp_is_premium', $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
42 function fleximp_license_admin_scripts($hook) {
43
44 if ($hook == 'flex-importer_page_fleximp-license-key') {
45 wp_enqueue_style('fleximp-license-css', FLEXIMP_PLUGIN_DIR_FILE . 'assets/css/fleximp-license-style.css', [], FLEXIMP_VER);
46 }
47
48 wp_enqueue_script('fleximp-notify-js', FLEXIMP_PLUGIN_DIR_FILE . '/assets/js/jquery.notify.min.js', [], FLEXIMP_VER);
49 wp_register_script(
50 'fleximp-license-admin-script',
51 FLEXIMP_PLUGIN_DIR_FILE . 'assets/js/license_script.js',
52 [],
53 FLEXIMP_VER
54 );
55
56 $localize_script_arr = array(
57 'ajaxurl' => admin_url('admin-ajax.php'),
58 'wpnonce' => wp_create_nonce('admin_script_nonce'),
59 );
60
61 wp_localize_script('fleximp-license-admin-script', 'localize_script_arr', $localize_script_arr);
62 wp_enqueue_script('fleximp-license-admin-script');
63 }
64
65
66 add_action('admin_enqueue_scripts', 'fleximp_license_admin_scripts');
67
68 function license_activate_fleximp()
69 {
70
71 if (empty($_POST['fleximp_is_premium'])) {
72 wp_send_json(['status' => false, 'msg' => 'License key is required.']);
73 }
74
75 $license_key = $_POST['fleximp_is_premium'];
76 $endpoint = FLEXIMP_LICENSE_URL . 'verifyTheme';
77
78 $body = [
79 'theme_license_key' => $license_key,
80 'site_url' => site_url(),
81 'plugin_text_domain' => 'flex-import',
82 ];
83 $body = wp_json_encode($body);
84
85 $options = [
86 'body' => $body,
87 'headers' => ['Content-Type' => 'application/json'],
88 ];
89
90 $response = wp_remote_post($endpoint, $options);
91
92 if (is_wp_error($response)) {
93 remove_fleximp_key();
94 set_fleximp_validation_status('false');
95 wp_send_json(['status' => false, 'msg' => 'Something Went Wrong!']);
96 } else {
97 $response_body = json_decode(wp_remote_retrieve_body($response));
98
99 if ($response_body->is_suspended == 1) {
100 set_fleximp_suspension_status('true');
101 } else {
102 set_fleximp_suspension_status('false');
103 }
104
105 if ($response_body->status === false) {
106 remove_fleximp_key();
107 set_fleximp_validation_status('false');
108 wp_send_json(['status' => false, 'msg' => $response_body->msg]);
109 } else {
110 set_fleximp_validation_status('true');
111 set_fleximp_key($license_key);
112 wp_send_json(['status' => true, 'msg' => 'Plugin Activated Successfully!']);
113 }
114 }
115 }
116
117 add_action('wp_ajax_license_activate_fleximp', 'license_activate_fleximp');
118
119 function license_deactivate_fleximp()
120 {
121 $license_key = $_POST['fleximp_is_premium'];
122
123 if ($license_key != '') {
124 $endpoint = FLEXIMP_LICENSE_URL . 'deactivateDomain';
125 $body = [
126 'theme_license_key' => $license_key,
127 'site_url' => site_url(),
128 ];
129 $body = wp_json_encode($body);
130
131 $options = [
132 'body' => $body,
133 'headers' => ['Content-Type' => 'application/json'],
134 ];
135
136 $response = wp_remote_post($endpoint, $options);
137
138 if (is_wp_error($response)) {
139 wp_send_json(['status' => false, 'msg' => 'Something Went Wrong!']);
140 } else {
141 $response_body = json_decode(wp_remote_retrieve_body($response));
142
143 if ($response_body->status === false) {
144 wp_send_json(['status' => false, 'msg' => $response_body->msg]);
145 } else {
146 remove_fleximp_key();
147 set_fleximp_validation_status('false');
148 wp_send_json(['status' => true, 'msg' => $response_body->msg]);
149 }
150 }
151 }
152 }
153 add_action('wp_ajax_license_deactivate_fleximp', 'license_deactivate_fleximp');
154
155 function fleximp_license_expiry_notice()
156 {
157 $license_key = get_fleximp_key();
158 $endpoint = FLEXIMP_LICENSE_URL . 'status';
159
160 $body = [
161 'theme_license_key' => $license_key,
162 'site_url' => site_url(),
163 'plugin_text_domain' => 'flex-import',
164 ];
165 $body = wp_json_encode($body);
166
167 if ($license_key != "") {
168 $response = wp_remote_post($endpoint, [
169 'body' => $body,
170 'headers' => ['Content-Type' => 'application/json'],
171 ]);
172
173 if (!is_wp_error($response)) {
174 $response_body = json_decode(wp_remote_retrieve_body($response));
175
176 if (isset($response_body->status) && $response_body->status === false) {
177 set_fleximp_validation_status('false');
178 echo '<div class="notice notice-error"><p>License key is expired!</p></div>';
179 }
180
181 if (isset($response_body->is_suspended) && $response_body->is_suspended == 1) {
182 set_fleximp_suspension_status('false');
183 echo '<div class="notice notice-error"><p>License key is suspended!</p></div>';
184 }
185 }
186 }
187 }
188 add_action('admin_notices', 'fleximp_license_expiry_notice');
189 // License key code end
190 ?>