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