PluginProbe ʕ •ᴥ•ʔ
Flex Import / 2.5
Flex Import v2.5
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 10 months ago class-template-importer.php 10 months ago flex-dashboard-post-api.php 10 months ago flex-get-api.php 10 months ago flex-get-templates-api.php 10 months ago fleximp-license-functions.php 10 months ago
fleximp-license-functions.php
180 lines
1 <?php
2 if (!defined('ABSPATH')) {
3 exit; // Exit if accessed directly.
4 }
5
6 function get_fleximp_validation_status() {
7 return get_option('fleximp_validation_status', 'false');
8 }
9
10 function set_fleximp_validation_status($is_valid) {
11 update_option('fleximp_validation_status', $is_valid);
12 }
13
14 function get_fleximp_suspension_status() {
15 return get_option('fleximp_suspension_status', 'false');
16 }
17
18 function set_fleximp_suspension_status($is_suspended) {
19 update_option('fleximp_suspension_status', $is_suspended);
20 }
21
22 function set_fleximp_key($license_key) {
23 update_option('fleximp_is_premium', $license_key);
24 }
25
26 function remove_fleximp_key() {
27 delete_option('fleximp_is_premium');
28 }
29
30 function get_fleximp_key() {
31 return get_option('fleximp_is_premium');
32 }
33
34
35 function fleximp_license_admin_scripts($hook) {
36
37 if ($hook == 'flex-importer_page_fleximp-license-key') {
38 wp_enqueue_style('fleximp-license-css', FLEXIMP_PLUGIN_DIR_FILE . 'assets/css/fleximp-license-style.css', [], FLEXIMP_VER);
39 }
40
41 wp_enqueue_script('fleximp-notify-js', FLEXIMP_PLUGIN_DIR_FILE . '/assets/js/jquery.notify.min.js', [], FLEXIMP_VER);
42 wp_register_script(
43 'fleximp-license-admin-script',
44 FLEXIMP_PLUGIN_DIR_FILE . 'assets/js/license_script.js',
45 [],
46 FLEXIMP_VER
47 );
48
49 $localize_script_arr = array(
50 'ajaxurl' => admin_url('admin-ajax.php'),
51 'wpnonce' => wp_create_nonce('admin_script_nonce'),
52 'redirect_url' => admin_url('admin.php?page=fleximp-template-importer'),
53 );
54
55 wp_localize_script('fleximp-license-admin-script', 'localize_script_arr', $localize_script_arr);
56 wp_enqueue_script('fleximp-license-admin-script');
57 }
58
59
60 add_action('admin_enqueue_scripts', 'fleximp_license_admin_scripts');
61
62 function license_activate_fleximp() {
63
64 if (empty($_POST['fleximp_is_premium'])) {
65 wp_send_json(['status' => false, 'msg' => 'License key is required.']);
66 }
67
68 $license_key = $_POST['fleximp_is_premium'];
69 $endpoint = FLEXIMP_LICENSE_URL . 'verifyTheme';
70
71 $body = [
72 'theme_license_key' => $license_key,
73 'site_url' => site_url(),
74 'plugin_text_domain' => 'flex-import',
75 ];
76 $body = wp_json_encode($body);
77
78 $options = [
79 'body' => $body,
80 'headers' => ['Content-Type' => 'application/json'],
81 ];
82
83 $response = wp_remote_post($endpoint, $options);
84
85 if (is_wp_error($response)) {
86 remove_fleximp_key();
87 set_fleximp_validation_status('false');
88 wp_send_json(['status' => false, 'msg' => 'Something Went Wrong!']);
89 } else {
90 $response_body = json_decode(wp_remote_retrieve_body($response));
91
92 if ($response_body->is_suspended == 1) {
93 set_fleximp_suspension_status('true');
94 } else {
95 set_fleximp_suspension_status('false');
96 }
97
98 if ($response_body->status === false) {
99 remove_fleximp_key();
100 set_fleximp_validation_status('false');
101 wp_send_json(['status' => false, 'msg' => $response_body->msg]);
102 } else {
103 set_fleximp_validation_status('true');
104 set_fleximp_key($license_key);
105 wp_send_json(['status' => true, 'msg' => 'Plugin Activated Successfully!']);
106 }
107 }
108 }
109
110 add_action('wp_ajax_license_activate_fleximp', 'license_activate_fleximp');
111
112 function license_deactivate_fleximp() {
113 $license_key = $_POST['fleximp_license_key'];
114
115 if ($license_key != '') {
116 $endpoint = FLEXIMP_LICENSE_URL . 'deactivateDomain';
117 $body = [
118 'theme_license_key' => $license_key,
119 'site_url' => site_url(),
120 ];
121 $body = wp_json_encode($body);
122
123 $options = [
124 'body' => $body,
125 'headers' => ['Content-Type' => 'application/json'],
126 ];
127
128 $response = wp_remote_post($endpoint, $options);
129
130 if (is_wp_error($response)) {
131 wp_send_json(['status' => false, 'msg' => 'Something Went Wrong!']);
132 } else {
133 $response_body = json_decode(wp_remote_retrieve_body($response));
134
135 if ($response_body->status === false) {
136 wp_send_json(['status' => false, 'msg' => $response_body->msg]);
137 } else {
138 remove_fleximp_key();
139 set_fleximp_validation_status('false');
140 wp_send_json(['status' => true, 'msg' => $response_body->msg]);
141 }
142 }
143 }
144 }
145 add_action('wp_ajax_license_deactivate_fleximp', 'license_deactivate_fleximp');
146
147 function fleximp_license_expiry_notice() {
148
149 $license_key = get_fleximp_key();
150 $endpoint = FLEXIMP_LICENSE_URL . 'status';
151
152 $body = [
153 'theme_license_key' => $license_key,
154 'site_url' => site_url(),
155 'plugin_text_domain' => 'flex-import',
156 ];
157 $body = wp_json_encode($body);
158
159 if ($license_key != "") {
160 $response = wp_remote_post($endpoint, [
161 'body' => $body,
162 'headers' => ['Content-Type' => 'application/json'],
163 ]);
164
165 if (!is_wp_error($response)) {
166 $response_body = json_decode(wp_remote_retrieve_body($response));
167
168 if (isset($response_body->status) && $response_body->status === false) {
169 set_fleximp_validation_status('false');
170 echo '<div class="notice notice-error"><p>License key is expired!</p></div>';
171 }
172
173 if (isset($response_body->is_suspended) && $response_body->is_suspended == 1) {
174 set_fleximp_suspension_status('false');
175 echo '<div class="notice notice-error"><p>License key is suspended!</p></div>';
176 }
177 }
178 }
179 }
180 add_action('admin_notices', 'fleximp_license_expiry_notice');