PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.2.1
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.2.1
4.0.8 4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.2 3.1.3 3.10.0 3.10.1 3.10.10 3.10.11 3.10.12 3.10.13 3.10.14 3.10.15 3.10.2 3.10.3 All 149 releases
← All changes | vendor/codeinwp/themeisle-sdk/src/Modules/Licenser.php +162 -632 3.10.133.2.1 View file →
@@ -12,9 +12,8 @@
12 12 namespace ThemeisleSDK\Modules;
13 13
14 14 // Exit if accessed directly.
15 15 use ThemeisleSDK\Common\Abstract_Module;
16 -use ThemeisleSDK\Loader;
17 16 use ThemeisleSDK\Product;
18 17
19 18 if ( ! defined( 'ABSPATH' ) ) {
20 19 exit;
@@ -23,33 +22,16 @@
23 22 /**
24 23 * Licenser module for ThemeIsle SDK.
25 24 */
26 25 class Licenser extends Abstract_Module {
26 +
27 27 /**
28 - * License VALID status string.
29 - */
30 - const STATUS_VALID = 'valid';
31 - /**
32 - * License NOT_ACTIVE status string.
33 - */
34 - const STATUS_NOT_ACTIVE = 'not_active';
35 - /**
36 - * License active expired status string.
37 - */
38 - const STATUS_ACTIVE_EXPIRED = 'active_expired';
39 - /**
40 28 * Number of max failed checks before showing the license message.
41 29 *
42 30 * @var int $max_failed Maximum failed checks allowed before show the notice
43 31 */
44 - private static $max_failed = 1;
32 + private static $max_failed = 5;
45 33 /**
46 - * Flag to check if the global actions were loaded.
47 - *
48 - * @var bool If the globals actions were loaded.
49 - */
50 - private static $globals_loaded = false;
51 - /**
52 34 * License key string.
53 35 *
54 36 * @var string $license_key The license key string
55 37 */
@@ -73,21 +55,8 @@
73 55 */
74 56 private $product_key;
75 57
76 58 /**
77 - * Holds local license object.
78 - *
79 - * @var null Local license object.
80 - */
81 - private $license_local = null;
82 - /**
83 - * Product namespace, used for fixed name filters/cli commands.
84 - *
85 - * @var string $namespace Product namespace.
86 - */
87 - private $namespace = null;
88 -
89 - /**
90 59 * Disable wporg updates for premium products.
91 60 *
92 61 * @param string $r Update payload.
93 62 * @param string $url The api url.
@@ -93,9 +62,9 @@
93 62 * @param string $url The api url.
94 63 *
95 64 * @return mixed List of themes to check for update.
96 65 */
97 - public function disable_wporg_update( $r, $url ) {
66 + function disable_wporg_update( $r, $url ) {
98 67
99 68 if ( 0 !== strpos( $url, 'https://api.wordpress.org/themes/update-check/' ) ) {
100 69 return $r;
101 70 }
@@ -105,9 +74,9 @@
105 74
106 75 unset( $themes->themes->{$this->product->get_slug()} );
107 76
108 77 // Encode the updated JSON response.
109 - $r['body']['themes'] = wp_json_encode( $themes );
78 + $r['body']['themes'] = json_encode( $themes );
110 79
111 80 return $r;
112 81 }
113 82
@@ -119,11 +88,8 @@
119 88 public function register_settings() {
120 89 if ( ! is_admin() ) {
121 90 return false;
122 91 }
123 - if ( apply_filters( $this->product->get_key() . '_hide_license_field', false ) ) {
124 - return;
125 - }
126 92 add_settings_field(
127 93 $this->product->get_key() . '_license',
128 94 $this->product->get_name() . ' license',
129 95 array( $this, 'license_view' ),
@@ -137,88 +103,24 @@
137 103 public function license_view() {
138 104 $status = $this->get_license_status();
139 105 $value = $this->license_key;
140 106
141 - $activate_string = apply_filters( $this->product->get_key() . '_lc_activate_string', Loader::$labels['licenser']['activate'] );
142 - $deactivate_string = apply_filters( $this->product->get_key() . '_lc_deactivate_string', Loader::$labels['licenser']['deactivateactivate'] );
143 - $valid_string = apply_filters( $this->product->get_key() . '_lc_valid_string', Loader::$labels['licenser']['valid'] );
144 - $invalid_string = apply_filters( $this->product->get_key() . '_lc_invalid_string', Loader::$labels['licenser']['invalid'] );
145 - $license_message = apply_filters( $this->product->get_key() . '_lc_license_message', Loader::$labels['licenser']['notice'] );
146 - $error_message = $this->get_error();
147 - ?>
148 - <style type="text/css">
149 - input.themeisle-sdk-text-input-valid {
150 - border: 1px solid #7ad03a;
151 - }
107 + $activate_string = apply_filters( $this->product->get_key() . '_lc_activate_string', 'Activate' );
108 + $deactivate_string = apply_filters( $this->product->get_key() . '_lc_deactivate_string', 'Deactivate' );
109 + $valid_string = apply_filters( $this->product->get_key() . '_lc_valid_string', 'Valid' );
110 + $invalid_string = apply_filters( $this->product->get_key() . '_lc_invalid_string', 'Invalid' );
111 + $license_message = apply_filters( $this->product->get_key() . '_lc_license_message', 'Enter your license from %s purchase history in order to get %s updates' );
152 112
153 - input.themeisle-sdk-license-input {
154 - width: 300px;
155 - padding: 0 8px;
156 - line-height: 2;
157 - min-height: 30px;
158 - }
113 + echo '<p ><input ' . ( ( 'valid' === $status ) ? ( 'style="border:1px solid #7ad03a; "' ) : '' ) . ' type="text" id="' . $this->product->get_key() . '_license" name="' . $this->product->get_key() . '_license" value="' . $value . '" /><a ' . ( ( 'valid' === $status ) ? ( 'style="color:#fff;background: #7ad03a; display: inline-block;text-decoration: none;font-size: 13px;line-height: 26px;height: 26px; margin-left:5px; padding: 0 10px 1px; -webkit-border-radius: 3px;border-radius: 3px; ">' . $valid_string ) : ( 'style="color:#fff;background: #dd3d36; display: inline-block;text-decoration: none;font-size: 13px;line-height: 26px;height: 26px; margin-left:5px; padding: 0 10px 1px; -webkit-border-radius: 3px;border-radius: 3px; ">' . $invalid_string ) ) . ' </a>&nbsp;&nbsp;&nbsp;<button name="' . $this->product->get_key() . '_btn_trigger" ' . ( ( 'valid' === $status ) ? ( ' class="button button-primary">' . $deactivate_string ) : ( ' class="button button-primary" value="yes" type="submit" >' . $activate_string ) ) . ' </button></p><p class="description">' . sprintf( $license_message, '<a href="' . $this->get_api_url() . '">' . $this->get_distributor_name() . '</a> ', $this->product->get_type() ) . '</p>';
159 114
160 - .themeisle-sdk-license-deactivate-cta {
161 - color: #fff;
162 - background: #7ad03a;
163 - display: inline-block;
164 - text-decoration: none;
165 - font-size: 13px;
166 - line-height: 30px;
167 - height: 26px;
168 - margin-left: 5px;
169 - padding: 0 10px 3px;
170 - -webkit-border-radius: 3px;
171 - border-radius: 3px;
172 - }
173 -
174 - .themeisle-sdk-license-activate-cta {
175 - color: #fff;
176 - background: #dd3d36;
177 - display: inline-block;
178 - text-decoration: none;
179 - font-size: 13px;
180 - line-height: 30px;
181 - height: 26px;
182 - margin-left: 5px;
183 - padding: 0 10px 3px;
184 - -webkit-border-radius: 3px;
185 - border-radius: 3px;
186 - }
187 -
188 - button.button.themeisle-sdk-licenser-button-cta {
189 - line-height: 26px;
190 - height: 29px;
191 - vertical-align: top;
192 - }
193 -
194 - </style>
195 - <?php
196 - echo sprintf(
197 - '<p>%s<input class="themeisle-sdk-license-input %s" type="text" id="%s_license" name="%s_license" value="%s" /><a class="%s">%s</a>&nbsp;&nbsp;&nbsp;<button name="%s_btn_trigger" class="button button-primary themeisle-sdk-licenser-button-cta" value="yes" type="submit" >%s</button></p><p class="description">%s</p>%s',
198 - ( ( 'valid' === $status ) ? sprintf( '<input type="hidden" value="%s" name="%s_license" />', esc_attr( $value ), esc_attr( $this->product->get_key() ) ) : '' ),
199 - ( ( 'valid' === $status ) ? 'themeisle-sdk-text-input-valid' : '' ),
200 - esc_attr( $this->product->get_key() ),
201 - esc_attr( ( ( 'valid' === $status ) ? $this->product->get_key() . '_mask' : $this->product->get_key() ) ),
202 - esc_attr( ( ( 'valid' === $status ) ? ( str_repeat( '*', 30 ) . substr( $value, - 5 ) ) : $value ) ),
203 - esc_attr( ( 'valid' === $status ? 'themeisle-sdk-license-deactivate-cta' : 'themeisle-sdk-license-activate-cta' ) ),
204 - esc_attr( 'valid' === $status ? $valid_string : $invalid_string ),
205 - esc_attr( $this->product->get_key() ),
206 - esc_attr( 'valid' === $status ? $deactivate_string : $activate_string ),
207 - sprintf( wp_kses_data( $license_message ), '<a href="' . esc_url( $this->get_api_url() ) . '">' . esc_attr( $this->get_distributor_name() ) . '</a> ', esc_attr( $this->product->get_type() ) ),
208 - wp_kses_data( empty( $error_message ) ? '' : sprintf( '<p style="color:#dd3d36">%s</p>', ( $error_message ) ) )
209 - ) . wp_nonce_field( $this->product->get_key() . 'nonce', $this->product->get_key() . 'nonce_field', false, false );//phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
210 -
211 115 }
212 116
213 117 /**
214 118 * Return the license status.
215 119 *
216 - * @param bool $check_expiration Should check if license is valid, but expired.
217 - *
218 120 * @return string The License status.
219 121 */
220 - public function get_license_status( $check_expiration = false ) {
122 + public function get_license_status() {
221 123
222 124 $license_data = get_option( $this->product->get_key() . '_license_data', '' );
223 125
224 126 if ( '' === $license_data ) {
@@ -223,113 +125,14 @@
223 125
224 126 if ( '' === $license_data ) {
225 127 return get_option( $this->product->get_key() . '_license_status', 'not_active' );
226 128 }
227 - $status = isset( $license_data->license ) ? $license_data->license : get_option( $this->product->get_key() . '_license_status', 'not_active' );
228 - if ( false === $check_expiration ) {
229 - return $status;
230 - }
231 129
232 - return ( 'valid' === $status && isset( $license_data->is_expired ) && 'yes' === $license_data->is_expired ) ? 'active_expired' : $status;
233 - }
130 + return isset( $license_data->license ) ? $license_data->license : get_option( $this->product->get_key() . '_license_status', 'not_active' );
234 131
235 - /**
236 - * Check status.
237 - *
238 - * @param string $product_file Product basefile.
239 - *
240 - * @return string Status license.
241 - */
242 - public static function status( $product_file ) {
243 - $product = Product::get( $product_file );
244 - if ( ! $product->requires_license() ) {
245 - return self::STATUS_VALID;
246 - }
247 - $license_data = self::get_license_data( $product->get_key() );
248 -
249 - $status = isset( $license_data->license ) ? $license_data->license : self::STATUS_NOT_ACTIVE;
250 -
251 - return ( 'valid' === $status && isset( $license_data->is_expired ) && 'yes' === $license_data->is_expired ) ? 'active_expired' : $status;
252 132 }
253 133
254 134 /**
255 - * Product license data.
256 - *
257 - * @param string $key Product key.
258 - *
259 - * @return false|mixed|null
260 - */
261 - private static function get_license_data( $key ) {
262 - $license_data = get_option( $key . '_license_data', '' );
263 -
264 - return isset( $license_data->license ) ? $license_data : false;
265 - }
266 -
267 - /**
268 - * Get license hash.
269 - *
270 - * @param string $key Product key.
271 - *
272 - * @return bool|string
273 - */
274 - public static function create_license_hash( $key ) {
275 - $data = self::get_license_data( $key );
276 -
277 - if ( ! $data ) {
278 - return false;
279 - }
280 -
281 - return isset( $data->key ) ? wp_hash( $data->key ) : false;
282 - }
283 -
284 - /**
285 - * Check if license is valid.
286 - *
287 - * @param string $product_file Product basefile.
288 - *
289 - * @return bool Is valid?
290 - */
291 - public static function is_valid( $product_file ) {
292 - return self::status( $product_file ) === self::STATUS_VALID;
293 - }
294 -
295 - /**
296 - * Get product plan.
297 - *
298 - * @param string $product_file Product file.
299 - *
300 - * @return int Plan id.
301 - */
302 - public static function plan( $product_file ) {
303 - $product = Product::get( $product_file );
304 - $data = self::get_license_data( $product->get_key() );
305 -
306 - return isset( $data->price_id ) ? (int) $data->price_id : - 1;
307 - }
308 -
309 - /**
310 - * Get product license key.
311 - *
312 - * @param string $product_file Product file.
313 - *
314 - * @return string
315 - */
316 - public static function key( $product_file ) {
317 - $product = Product::get( $product_file );
318 -
319 - return $product->get_license();
320 - }
321 -
322 - /**
323 - * Return the last error message.
324 - *
325 - * @return mixed Error message.
326 - */
327 - public function get_error() {
328 - return get_transient( $this->product->get_key() . 'act_err' );
329 - }
330 -
331 - /**
332 135 * Get remote api url.
333 136 *
334 137 * @return string Remote api url.
335 138 */
@@ -347,9 +150,9 @@
347 150 * @return string Remote api url.
348 151 */
349 152 public function get_distributor_name() {
350 153 if ( $this->is_from_partner( $this->product ) ) {
351 - return 'Themeisle';
154 + return 'ThemeIsle';
352 155 }
353 156
354 157 return $this->product->get_store_name();
355 158 }
@@ -354,34 +157,21 @@
354 157 return $this->product->get_store_name();
355 158 }
356 159
357 160 /**
358 - * License price id.
359 - *
360 - * @return int License plan.
361 - */
362 - public function get_plan() {
363 - return self::plan( $this->product->get_basefile() );
364 - }
365 -
366 - /**
367 161 * Show the admin notice regarding the license status.
368 162 *
369 163 * @return bool Should we show the notice ?
370 164 */
371 - public function show_notice() {
165 + function show_notice() {
372 166 if ( ! is_admin() ) {
373 167 return false;
374 168 }
169 + $status = $this->get_license_status();
170 + $no_activations_string = apply_filters( $this->product->get_key() . '_lc_no_activations_string', 'No activations left for %s !!!. You need to upgrade your plan in order to use %s on more websites. Please ask the %s Staff for more details.' );
171 + $no_valid_string = apply_filters( $this->product->get_key() . '_lc_no_valid_string', 'In order to benefit from updates and support for %s, please add your license code from your <a href="%s" target="_blank">purchase history</a> and validate it <a href="%s">here</a>. ' );
172 + $expiration_string = apply_filters( $this->product->get_key() . '_lc_expiration_string', 'Your license is about to expire for %s. You can go to %s and renew it ' );
375 173
376 - if ( apply_filters( $this->product->get_key() . '_hide_license_notices', false ) ) {
377 - return false;
378 - }
379 -
380 - $status = $this->get_license_status( true );
381 - $no_activations_string = apply_filters( $this->product->get_key() . '_lc_no_activations_string', Loader::$labels['licenser']['no_activations'] );
382 - $no_valid_string = apply_filters( $this->product->get_key() . '_lc_no_valid_string', sprintf( Loader::$labels['licenser']['inactive'], '%s', '<a href="%s" target="_blank">', '</a>', '<a href="%s">', '</a>' ) );
383 - $expired_license_string = apply_filters( $this->product->get_key() . '_lc_expired_string', sprintf( Loader::$labels['licenser']['expired'], '%s', '<a href="%s" target="_blank">', '</a>' ) );
384 174 // No activations left for this license.
385 175 if ( 'valid' != $status && $this->check_activation() ) {
386 176 ?>
387 177 <div class="error">
@@ -387,12 +177,12 @@
387 177 <div class="error">
388 178 <p><strong>
389 179 <?php
390 180 echo sprintf(
391 - wp_kses_data( $no_activations_string ),
392 - esc_attr( $this->product->get_name() ),
393 - esc_attr( $this->product->get_name() ),
394 - '<a href="' . esc_url( $this->get_api_url() ) . '" target="_blank">' . esc_attr( $this->get_distributor_name() ) . '</a>'
181 + $no_activations_string,
182 + $this->product->get_name(),
183 + $this->product->get_name(),
184 + '<a href="' . $this->get_api_url() . '" target="_blank">' . $this->get_distributor_name() . '</a>'
395 185 );
396 186 ?>
397 187 </strong>
398 188 </p>
@@ -399,15 +189,14 @@
399 189 </div>
400 190 <?php
401 191 return false;
402 192 }
403 -
404 193 // Invalid license key.
405 - if ( 'active_expired' === $status ) {
194 + if ( 'valid' != $status ) {
406 195 ?>
407 196 <div class="error">
408 197 <p>
409 - <strong><?php echo sprintf( wp_kses_data( $expired_license_string ), esc_attr( $this->product->get_name() . ' ' . $this->product->get_type() ), esc_url( $this->get_api_url() . '?license=' . $this->license_key ) ); ?> </strong>
198 + <strong><?php echo sprintf( $no_valid_string, $this->product->get_name() . ' ' . $this->product->get_type(), $this->get_api_url(), admin_url( 'options-general.php' ) . '#' . $this->product->get_key() ); ?> </strong>
410 199 </p>
411 200 </div>
412 201 <?php
413 202
@@ -412,18 +201,26 @@
412 201 <?php
413 202
414 203 return false;
415 204 }
416 - // Invalid license key.
417 - if ( 'valid' != $status ) {
205 +
206 + // Expired and soon to expire license.
207 + if ( 'valid' == $status && $this->check_expiration() ) {
418 208 ?>
419 - <div class="error">
209 + <div class="update-nag">
420 210 <p>
421 - <strong><?php echo sprintf( wp_kses_data( $no_valid_string ), esc_attr( $this->product->get_name() . ' ' . $this->product->get_type() ), esc_url( $this->get_api_url() ), esc_url( admin_url( 'options-general.php' ) . '#' . $this->product->get_key() . '_license' ) ); ?> </strong>
211 + <strong>
212 + <?php
213 + echo sprintf(
214 + $expiration_string,
215 + $this->product->get_name() . ' ' . $this->product->get_type(),
216 + '<a href="' . $this->renew_url() . '" target="_blank">' . $this->get_distributor_name() . '</a>'
217 + );
218 + ?>
219 + </strong>
422 220 </p>
423 221 </div>
424 222 <?php
425 -
426 223 return false;
427 224 }
428 225
429 226 return true;
@@ -439,9 +236,9 @@
439 236 if ( '' === $license_data ) {
440 237 return false;
441 238 }
442 239
443 - return isset( $license_data->license ) ? ( 'no_activations_left' == $license_data->license ) : false;
240 + return isset( $license_data->error ) ? ( 'no_activations_left' == $license_data->error ) : false;
444 241
445 242 }
446 243
447 244 /**
@@ -448,9 +245,9 @@
448 245 * Check if the license is about to expire in the next month.
449 246 *
450 247 * @return bool
451 248 */
452 - public function check_expiration() {
249 + function check_expiration() {
453 250 $license_data = get_option( $this->product->get_key() . '_license_data', '' );
454 251 if ( '' === $license_data ) {
455 252 return false;
456 253 }
@@ -468,9 +265,9 @@
468 265 * Return the renew url from the store used.
469 266 *
470 267 * @return string The renew url.
471 268 */
472 - public function renew_url() {
269 + function renew_url() {
473 270 $license_data = get_option( $this->product->get_key() . '_license_data', '' );
474 271 if ( '' === $license_data ) {
475 272 return $this->get_api_url();
476 273 }
@@ -477,9 +274,9 @@
477 274 if ( ! isset( $license_data->download_id ) || ! isset( $license_data->key ) ) {
478 275 return $this->get_api_url();
479 276 }
480 277
481 - return trim( $this->get_api_url(), '/' ) . '/checkout/?edd_license_key=' . $license_data->key . '&download_id=' . $license_data->download_id;
278 + return $this->get_api_url() . '/checkout/?edd_license_key=' . $license_data->key . '&download_id=' . $license_data->download_id;
482 279 }
483 280
484 281 /**
485 282 * Run the license check call.
@@ -484,9 +281,9 @@
484 281 /**
485 282 * Run the license check call.
486 283 */
487 284 public function product_valid() {
488 - if ( false !== ( $license = get_transient( $this->product->get_key() . '_license_data' ) ) ) { //phpcs:ignore Squiz.PHP.DisallowMultipleAssignments.FoundInControlStructure
285 + if ( false !== ( $license = get_transient( $this->product->get_key() . '_license_data' ) ) ) {
489 286 return;
490 287 }
491 288 $license = $this->check_license();
492 289 set_transient( $this->product->get_key() . '_license_data', $license, 12 * HOUR_IN_SECONDS );
@@ -499,149 +296,84 @@
499 296 * @return object The license data.
500 297 */
501 298 public function check_license() {
502 299 $status = $this->get_license_status();
503 - if ( 'not_active' === $status ) {
300 + if ( 'not_active' == $status ) {
504 301 $license_data = new \stdClass();
505 302 $license_data->license = 'not_active';
506 303
507 304 return $license_data;
508 305 }
509 - $license = trim( $this->license_key );
510 -
511 - $response = $this->do_license_process( $license, 'check' );
512 -
306 + $license = trim( $this->license_key );
307 + $api_params = array(
308 + 'edd_action' => 'check_license',
309 + 'license' => $license,
310 + 'item_name' => rawurlencode( $this->product->get_name() ),
311 + 'url' => rawurlencode( home_url() ),
312 + );
313 + // Call the custom API.
314 + $response = wp_remote_get(
315 + add_query_arg( $api_params, $this->get_api_url() ),
316 + array(
317 + 'timeout' => 15,
318 + 'sslverify' => false,
319 + )
320 + );
513 321 if ( is_wp_error( $response ) ) {
514 322 $license_data = new \stdClass();
515 - $license_data->license = 'invalid';
323 + $license_data->license = 'valid';
324 +
516 325 } else {
517 - $license_data = $response;
326 + $license_data = json_decode( wp_remote_retrieve_body( $response ) );
327 + if ( ! is_object( $license_data ) ) {
328 + $license_data = new \stdClass();
329 + $license_data->license = 'valid';
330 + }
518 331 }
519 -
520 332 $license_old = get_option( $this->product->get_key() . '_license_data', '' );
521 - if ( 'valid' === $license_old->license && ( $license_data->license !== $license_old->license ) && $this->failed_checks <= self::$max_failed ) {
333 + if ( 'valid' == $license_old->license && ( $license_data->license != $license_old->license ) ) {
522 334 $this->increment_failed_checks();
523 -
524 - return $license_old;
525 - }
526 -
527 - if ( ! isset( $license_data->key ) ) {
528 - $license_data->key = isset( $license_old->key ) ? $license_old->key : '';
529 - }
530 - $this->reset_failed_checks();
531 -
532 - return $license_data;
533 -
534 - }
535 -
536 - /**
537 - * Do license activation/deactivation.
538 - *
539 - * @param string $license License key.
540 - * @param string $action What do to.
541 - *
542 - * @return bool|\WP_Error
543 - */
544 - public function do_license_process( $license, $action = 'toggle' ) {
545 - if ( strlen( $license ) < 10 ) {
546 - return new \WP_Error( 'themeisle-license-invalid-format', Loader::$labels['licenser']['invalid_msg'] );
547 - }
548 - $status = $this->get_license_status();
549 -
550 - if ( 'valid' === $status && 'activate' === $action ) {
551 - return new \WP_Error( 'themeisle-license-already-active', Loader::$labels['licenser']['already_active'] );
552 - }
553 - if ( 'valid' !== $status && 'deactivate' === $action ) {
554 - return new \WP_Error( 'themeisle-license-already-deactivate', Loader::$labels['licenser']['not_active'] );
555 - }
556 -
557 - if ( 'toggle' === $action ) {
558 - $action = ( 'valid' !== $status ? ( 'activate' ) : ( 'deactivate' ) );
559 - }
560 -
561 - // Call the custom API.
562 - if ( 'check' === $action ) {
563 - $response = $this->safe_get( sprintf( '%slicense/check/%s/%s/%s/%s', Product::API_URL, rawurlencode( $this->product->get_name() ), $license, rawurlencode( home_url() ), Loader::get_cache_token() ) );
564 335 } else {
565 - $response = wp_remote_post(
566 - sprintf( '%slicense/%s/%s/%s', Product::API_URL, $action, rawurlencode( $this->product->get_name() ), $license ),
567 - array(
568 - 'body' => wp_json_encode(
569 - array(
570 - 'url' => rawurlencode( home_url() ),
571 - )
572 - ),
573 - 'headers' => array(
574 - 'Content-Type' => 'application/json',
575 - ),
576 - )
577 - );
336 + $this->reset_failed_checks();
578 337 }
579 338
580 - // make sure the response came back okay.
581 - if ( is_wp_error( $response ) ) {
582 - return new \WP_Error( 'themeisle-license-500', sprintf( Loader::$labels['licenser']['error_notice'], $response->get_error_message() ) );
339 + if ( $this->failed_checks <= self::$max_failed ) {
340 + return $license_old;
583 341 }
584 342
585 - $license_data = json_decode( wp_remote_retrieve_body( $response ) );
586 -
587 - if ( ! is_object( $license_data ) ) {
588 - return new \WP_Error( 'themeisle-license-404', Loader::$labels['licenser']['error_notice2'] );
343 + if ( isset( $license_old->hide_valid ) ) {
344 + $license_data->hide_valid = true;
589 345 }
590 - if ( 'check' === $action ) {
591 - return $license_data;
592 - }
593 346
594 - Loader::clear_cache_token();
595 -
596 - if ( ! isset( $license_data->license ) ) {
597 - $license_data->license = 'invalid';
347 + if ( ! isset( $license_data->key ) ) {
348 + $license_data->key = isset( $license_old->key ) ? $license_old->key : '';
598 349 }
599 350
600 - if ( ! isset( $license_data->key ) ) {
601 - $license_data->key = $license;
351 + if ( isset( $license_old->hide_expiration ) ) {
352 + $license_data->hide_expiration = true;
602 353 }
603 - if ( 'valid' === $license_data->license ) {
604 - $this->reset_failed_checks();
605 - }
606 354
607 - if ( 'deactivate' === $action ) {
608 -
609 - delete_option( $this->product->get_key() . '_license_data' );
610 - delete_option( $this->product->get_key() . '_license_plan' );
611 - delete_transient( $this->product->get_key() . '_license_data' );
612 -
613 - return true;
355 + if ( isset( $license_old->hide_activation ) ) {
356 + $license_data->hide_activation = true;
614 357 }
615 - if ( isset( $license_data->plan ) ) {
616 - update_option( $this->product->get_key() . '_license_plan', $license_data->plan );
617 - }
618 - update_option( $this->product->get_key() . '_license_data', $license_data );
619 - set_transient( $this->product->get_key() . '_license_data', $license_data, 12 * HOUR_IN_SECONDS );
620 - if ( 'activate' === $action && 'valid' !== $license_data->license ) {
621 - return new \WP_Error( 'themeisle-license-invalid', Loader::$labels['licenser']['error_invalid'] );
622 - }
623 358
624 - // Remove the versions transient upon activation so that newer version for rollback can be acquired.
625 - $versions_cache = $this->product->get_cache_key();
626 - delete_transient( $versions_cache );
359 + return $license_data;
627 360
628 - return true;
629 361 }
630 362
631 363 /**
632 - * Reset the failed checks
364 + * Increment the failed checks.
633 365 */
634 - private function reset_failed_checks() {
635 - $this->failed_checks = 1;
366 + private function increment_failed_checks() {
367 + $this->failed_checks ++;
636 368 update_option( $this->product->get_key() . '_failed_checks', $this->failed_checks );
637 369 }
638 370
639 371 /**
640 - * Increment the failed checks.
372 + * Reset the failed checks
641 373 */
642 - private function increment_failed_checks() {
643 - $this->failed_checks ++;
374 + private function reset_failed_checks() {
375 + $this->failed_checks = 1;
644 376 update_option( $this->product->get_key() . '_failed_checks', $this->failed_checks );
645 377 }
646 378
647 379 /**
@@ -646,50 +378,64 @@
646 378
647 379 /**
648 380 * Activate the license remotely.
649 381 */
650 - public function process_license() {
382 + function activate_license() {
651 383 // listen for our activate button to be clicked.
652 384 if ( ! isset( $_POST[ $this->product->get_key() . '_btn_trigger' ] ) ) {
653 385 return;
654 386 }
655 - if ( ! isset( $_POST[ $this->product->get_key() . 'nonce_field' ] )
656 - || ! wp_verify_nonce( $_POST[ $this->product->get_key() . 'nonce_field' ], $this->product->get_key() . 'nonce' ) //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
657 - ) {
658 - return;
387 + $status = $this->get_license_status();
388 + // retrieve the license from the database.
389 + $license = $_POST[ $this->product->get_key() . '_license' ];
390 + $api_params = array(
391 + 'license' => $license,
392 + 'item_name' => rawurlencode( $this->product->get_name() ),
393 + 'url' => rawurlencode( home_url() ),
394 + );
395 + if ( 'valid' != $status ) {
396 + // data to send in our API request.
397 + $api_params['edd_action'] = 'activate_license';
398 + } else {
399 + $api_params['edd_action'] = 'deactivate_license';
659 400 }
660 - if ( ! current_user_can( 'manage_options' ) ) {
661 - return;
662 - }
663 - $license = isset( $_POST[ $this->product->get_key() . '_license' ] )
664 - ? sanitize_text_field( $_POST[ $this->product->get_key() . '_license' ] )
665 - : '';
666 -
667 - $response = $this->do_license_process( $license, 'toggle' );
401 + // Call the custom API.
402 + $response = wp_remote_get( add_query_arg( $api_params, $this->get_api_url() ) );
403 + // make sure the response came back okay.
668 404 if ( is_wp_error( $response ) ) {
669 - $this->set_error( $response->get_error_message() );
405 + $license_data = new \stdClass();
406 + $license_data->license = ( 'valid' != $status ) ? 'valid' : 'invalid';
670 407
671 - return;
408 + } else {
409 + $license_data = json_decode( wp_remote_retrieve_body( $response ) );
410 + if ( ! is_object( $license_data ) ) {
411 + $license_data = new \stdClass();
412 + $license_data->license = ( 'valid' != $status ) ? 'valid' : 'invalid';
413 + }
414 + if ( ! isset( $license_data->license ) ) {
415 + $license_data->license = 'invalid';
416 + }
672 417 }
673 - if ( true === $response ) {
674 - $this->set_error( '' );
418 + if ( ! isset( $license_data->key ) ) {
419 + $license_data->key = $license;
675 420 }
676 - }
421 + if ( 'valid' == $license_data->license ) {
422 + $this->reset_failed_checks();
423 + }
677 424
678 - /**
679 - * Set license validation error message.
680 - *
681 - * @param string $message Error message.
682 - */
683 - public function set_error( $message = '' ) {
684 - set_transient( $this->product->get_key() . 'act_err', $message, MINUTE_IN_SECONDS );
425 + if ( isset( $license_data->plan ) ) {
426 + update_option( $this->product->get_key() . '_license_plan', $license_data->plan );
427 + }
685 428
429 + update_option( $this->product->get_key() . '_license_data', $license_data );
430 + set_transient( $this->product->get_key() . '_license_data', $license_data, 12 * HOUR_IN_SECONDS );
431 +
686 432 }
687 433
688 434 /**
689 435 * Load the Themes screen.
690 436 */
691 - public function load_themes_screen() {
437 + function load_themes_screen() {
692 438 add_thickbox();
693 439 add_action( 'admin_notices', array( &$this, 'update_nag' ) );
694 440 }
695 441
@@ -695,29 +441,31 @@
695 441
696 442 /**
697 443 * Alter the nag for themes update.
698 444 */
699 - public function update_nag() {
445 + function update_nag() {
700 446 $theme = wp_get_theme( $this->product->get_slug() );
701 447 $api_response = get_transient( $this->product_key );
702 - if ( false === $api_response || ! isset( $api_response->new_version ) ) {
448 + if ( false === $api_response ) {
703 449 return;
704 450 }
705 451 $update_url = wp_nonce_url( 'update.php?action=upgrade-theme&amp;theme=' . urlencode( $this->product->get_slug() ), 'upgrade-theme_' . $this->product->get_slug() );
706 - $update_message = apply_filters( 'themeisle_sdk_license_update_message', Loader::$labels['licenser']['update_license'] );
452 + $update_message = apply_filters( 'themeisle_sdk_license_update_message', 'Updating this theme will lose any customizations you have made. Cancel to stop, OK to update.' );
707 453 $update_onclick = ' onclick="if ( confirm(\'' . esc_js( $update_message ) . '\') ) {return true;}return false;"';
708 454 if ( version_compare( $this->product->get_version(), $api_response->new_version, '<' ) ) {
709 455 echo '<div id="update-nag">';
710 456 printf(
711 - esc_html( Loader::$labels['licenser']['notice_update'] ),
712 - '<strong>' . esc_attr( $theme->get( 'Name' ) ) . ' ' . esc_attr( $api_response->new_version ) . '</strong>',
713 - '<a href="' . esc_url( sprintf( '%s&TB_iframe=true&amp;width=1024&amp;height=800', $this->product->get_changelog() ) ) . '" class="thickbox" title="' . esc_attr( $theme->get( 'Name' ) ) . '">',
714 - '</a>',
715 - '<a href="' . esc_url( $update_url ) . '" ' . $update_onclick . '>' // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped, Already escaped.
457 + '<strong>%1$s %2$s</strong> is available. <a href="%3$s" class="thickbox" title="%4s">Check out what\'s new</a> or <a href="%5$s"%6$s>update now</a>.',
458 + $theme->get( 'Name' ),
459 + $api_response->new_version,
460 + '#TB_inline?width=640&amp;inlineId=' . $this->product->get_version() . '_changelog',
461 + $theme->get( 'Name' ),
462 + $update_url,
463 + $update_onclick
716 464 );
717 465 echo '</div>';
718 - echo '<div id="' . esc_attr( $this->product->get_slug() ) . '_changelog" style="display:none;">';
719 - echo wp_kses_data( wpautop( $api_response->sections['changelog'] ) );
466 + echo '<div id="' . $this->product->get_slug() . '_' . 'changelog" style="display:none;">';
467 + echo wpautop( $api_response->sections['changelog'] );
720 468 echo '</div>';
721 469 }
722 470 }
723 471
@@ -727,24 +475,14 @@
727 475 * @param mixed $value The transient data.
728 476 *
729 477 * @return mixed
730 478 */
731 - public function theme_update_transient( $value ) {
479 + function theme_update_transient( $value ) {
732 480 $update_data = $this->check_for_update();
733 - if ( empty( $value ) ) {
734 - return $value;
481 + if ( $update_data ) {
482 + $value->response[ $this->product->get_slug() ] = $update_data;
735 483 }
736 484
737 - if ( ! isset( $value->response ) ) {
738 - return $value;
739 - }
740 -
741 - if ( ! $update_data ) {
742 - return $value;
743 - }
744 -
745 - $value->response[ $this->product->get_slug() ] = $update_data;
746 -
747 485 return $value;
748 486 }
749 487
750 488 /**
@@ -751,9 +489,9 @@
751 489 * Check for updates
752 490 *
753 491 * @return array|bool Either the update data or false in case of failure.
754 492 */
755 - public function check_for_update() {
493 + function check_for_update() {
756 494 $update_data = get_transient( $this->product_key );
757 495
758 496 if ( false === $update_data ) {
759 497 $failed = false;
@@ -768,9 +506,9 @@
768 506 set_transient( $this->product_key, $data, 30 * MINUTE_IN_SECONDS );
769 507
770 508 return false;
771 509 }
772 - $update_data->sections = isset( $update_data->sections ) ? maybe_unserialize( $update_data->sections ) : null;
510 + $update_data->sections = maybe_unserialize( $update_data->sections );
773 511
774 512 set_transient( $this->product_key, $update_data, 12 * HOUR_IN_SECONDS );
775 513 }
776 514 if ( ! isset( $update_data->new_version ) ) {
@@ -788,21 +526,23 @@
788 526 *
789 527 * @return bool|mixed Update api response.
790 528 */
791 529 private function get_version_data() {
792 -
793 - $response = $this->safe_get(
794 - sprintf(
795 - '%slicense/version/%s/%s/%s/%s',
796 - Product::API_URL,
797 - rawurlencode( $this->product->get_name() ),
798 - ( empty( $this->license_key ) ? 'free' : $this->license_key ),
799 - $this->product->get_version(),
800 - rawurlencode( home_url() )
801 - ),
530 + $api_params = array(
531 + 'edd_action' => 'get_version',
532 + 'version' => $this->product->get_version(),
533 + 'license' => $this->license_key,
534 + 'name' => $this->product->get_name(),
535 + 'slug' => $this->product->get_slug(),
536 + 'author' => $this->get_distributor_name(),
537 + 'url' => rawurlencode( home_url() ),
538 + );
539 + $response = wp_remote_get(
540 + $this->get_api_url(),
802 541 array(
803 - 'timeout' => 15, //phpcs:ignore WordPressVIPMinimum.Performance.RemoteRequestTimeout.timeout_timeout, Inherited by wp_remote_get only, for vip environment we use defaults.
542 + 'timeout' => 15,
804 543 'sslverify' => false,
544 + 'body' => $api_params,
805 545 )
806 546 );
807 547 if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) ) {
808 548 return false;
@@ -810,17 +550,8 @@
810 550 $update_data = json_decode( wp_remote_retrieve_body( $response ) );
811 551 if ( ! is_object( $update_data ) ) {
812 552 return false;
813 553 }
814 - if ( isset( $update_data->slug ) ) {
815 - $update_data->slug = $this->product->get_slug();
816 - }
817 - if ( isset( $update_data->icons ) ) {
818 - $update_data->icons = (array) $update_data->icons;
819 - }
820 - if ( isset( $update_data->banners ) ) {
821 - $update_data->banners = (array) $update_data->banners;
822 - }
823 554
824 555 return $update_data;
825 556 }
826 557
@@ -826,10 +557,10 @@
826 557
827 558 /**
828 559 * Delete the update transient
829 560 */
830 - public function delete_theme_update_transient() {
831 - return delete_transient( $this->product_key );
561 + function delete_theme_update_transient() {
562 + delete_transient( $this->product_key );
832 563 }
833 564
834 565 /**
835 566 * Check for Updates at the defined API endpoint and modify the update array.
@@ -845,15 +576,10 @@
845 576 return $_transient_data;
846 577 }
847 578 $api_response = $this->api_request();
848 579 if ( false !== $api_response && is_object( $api_response ) && isset( $api_response->new_version ) ) {
849 - if ( ! isset( $api_response->plugin ) ) {
850 - $api_response->plugin = $this->product->get_slug() . '/' . $this->product->get_file();
851 - }
852 580 if ( version_compare( $this->product->get_version(), $api_response->new_version, '<' ) ) {
853 581 $_transient_data->response[ $this->product->get_slug() . '/' . $this->product->get_file() ] = $api_response;
854 - } else {
855 - $_transient_data->no_update[ $this->product->get_slug() . '/' . $this->product->get_file() ] = $api_response;
856 582 }
857 583 }
858 584
859 585 return $_transient_data;
@@ -888,9 +614,9 @@
888 614 *
889 615 * @return object $_data
890 616 */
891 617 public function plugins_api_filter( $_data, $_action = '', $_args = null ) {
892 - if ( ( 'plugin_information' !== $_action ) || ! isset( $_args->slug ) || ( $_args->slug !== $this->product->get_slug() ) ) {
618 + if ( ( 'plugin_information' != $_action ) || ! isset( $_args->slug ) || ( $_args->slug != $this->product->get_slug() ) ) {
893 619 return $_data;
894 620 }
895 621 $api_response = $this->api_request();
896 622 if ( false !== $api_response ) {
@@ -907,9 +633,9 @@
907 633 * @param string $url Url to check.
908 634 *
909 635 * @return array $array
910 636 */
911 - public function http_request_args( $args, $url ) {
637 + function http_request_args( $args, $url ) {
912 638 // If it is an https request and we are performing a package download, disable ssl verification.
913 639 if ( strpos( $url, 'https://' ) !== false && strpos( $url, 'edd_action=package_download' ) ) {
914 640 $args['sslverify'] = false;
915 641 }
@@ -950,31 +676,9 @@
950 676 if ( $this->product->requires_license() ) {
951 677 $this->failed_checks = intval( get_option( $this->product->get_key() . '_failed_checks', 0 ) );
952 678 $this->register_license_hooks();
953 679 }
954 - if ( ! self::$globals_loaded ) {
955 - add_filter( 'themeisle_sdk_license/status', [ __CLASS__, 'status' ], 999, 1 );
956 - add_filter( 'themeisle_sdk_license/is-valid', [ __CLASS__, 'is_valid' ], 999, 1 );
957 - add_filter( 'themeisle_sdk_license/plan', [ __CLASS__, 'plan' ], 999, 1 );
958 - add_filter( 'themeisle_sdk_license/key', [ __CLASS__, 'key' ], 999, 1 );
959 - $globals_loaded = true;
960 - }
961 - $namespace = apply_filters( 'themesle_sdk_namespace_' . md5( $product->get_basefile() ), false );
962 680
963 - if ( false !== $namespace ) {
964 - $this->namespace = $namespace;
965 - add_filter( 'themeisle_sdk_license_process_' . $namespace, [ $this, 'do_license_process' ], 10, 2 );
966 - add_filter( 'product_' . $namespace . '_license_status', [ $this, 'get_license_status' ], PHP_INT_MAX );
967 - add_filter( 'product_' . $namespace . '_license_key', [ $this->product, 'get_license' ] );
968 - add_filter( 'product_' . $namespace . '_license_plan', [ $this, 'get_plan' ], PHP_INT_MAX );
969 - if ( defined( 'WP_CLI' ) && WP_CLI ) {
970 - \WP_CLI::add_command( $namespace . ' activate', [ $this, 'cli_activate' ] );
971 - \WP_CLI::add_command( $namespace . ' deactivate', [ $this, 'cli_deactivate' ] );
972 - \WP_CLI::add_command( $namespace . ' is-active', [ $this, 'cli_is_active' ] );
973 - }
974 - }
975 -
976 - add_action( 'admin_head', [ $this, 'auto_activate' ] );
977 681 if ( $this->product->is_plugin() ) {
978 682 add_filter(
979 683 'pre_set_site_transient_update_plugins',
980 684 [
@@ -982,49 +686,19 @@
982 686 'pre_set_site_transient_update_plugins_filter',
983 687 ]
984 688 );
985 689 add_filter( 'plugins_api', array( $this, 'plugins_api_filter' ), 10, 3 );
986 - add_filter( //phpcs:ignore WordPressVIPMinimum.Hooks.RestrictedHooks.http_request_args
987 - 'http_request_args',
988 - array(
989 - $this,
990 - 'http_request_args',
991 - ),
992 - 10,
993 - 2
994 - );
995 - if ( ! self::is_valid( $product->get_basefile() ) ) {
996 - add_filter(
997 - 'plugin_action_links_' . plugin_basename( $product->get_basefile() ),
998 - function ( $actions ) {
999 - if ( $this->get_license_status( true ) !== self::STATUS_ACTIVE_EXPIRED ) {
1000 - return $actions;
1001 - }
1002 - $new_actions['deactivate'] = $actions['deactivate'];
1003 - $new_actions['renew_link'] = '<a style="color:#d63638" href="' . esc_url( $this->renew_url() ) . '" target="_blank" rel="external noopener noreferrer">' . esc_html( Loader::$labels['licenser']['renew_cta'] ) . '</a>';
690 + add_filter( 'http_request_args', array( $this, 'http_request_args' ), 10, 2 );
1004 691
1005 - return $new_actions;
1006 - }
1007 - );
1008 - }
1009 -
1010 692 return $this;
1011 693 }
1012 694 if ( $this->product->is_theme() ) {
1013 695 add_filter( 'site_transient_update_themes', array( &$this, 'theme_update_transient' ) );
1014 - add_action( 'delete_site_transient_update_themes', array( &$this, 'delete_theme_update_transient' ) );
696 + add_filter( 'delete_site_transient_update_themes', array( &$this, 'delete_theme_update_transient' ) );
1015 697 add_action( 'load-update-core.php', array( &$this, 'delete_theme_update_transient' ) );
1016 698 add_action( 'load-themes.php', array( &$this, 'delete_theme_update_transient' ) );
1017 699 add_action( 'load-themes.php', array( &$this, 'load_themes_screen' ) );
1018 - add_filter( //phpcs:ignore WordPressVIPMinimum.Hooks.RestrictedHooks.http_request_args
1019 - 'http_request_args',
1020 - array(
1021 - $this,
1022 - 'disable_wporg_update',
1023 - ),
1024 - 5,
1025 - 2
1026 - );
700 + add_filter( 'http_request_args', array( $this, 'disable_wporg_update' ), 5, 2 );
1027 701
1028 702 return $this;
1029 703
1030 704 }
@@ -1036,154 +710,10 @@
1036 710 * Register license fields for the products.
1037 711 */
1038 712 public function register_license_hooks() {
1039 713 add_action( 'admin_init', array( $this, 'register_settings' ) );
1040 - add_action( 'admin_init', array( $this, 'process_license' ) );
714 + add_action( 'admin_init', array( $this, 'activate_license' ) );
1041 715 add_action( 'admin_init', array( $this, 'product_valid' ), 99999999 );
1042 716 add_action( 'admin_notices', array( $this, 'show_notice' ) );
1043 717 add_filter( $this->product->get_key() . '_license_status', array( $this, 'get_license_status' ) );
1044 - }
1045 -
1046 - /**
1047 - * Check license on filesystem.
1048 - *
1049 - * @return mixed License key.
1050 - */
1051 - public function get_file_license() {
1052 -
1053 - $license_file = dirname( $this->product->get_basefile() ) . '/license.json';
1054 -
1055 - global $wp_filesystem;
1056 - if ( ! is_file( $license_file ) ) {
1057 - return false;
1058 - }
1059 -
1060 - require_once ABSPATH . '/wp-admin/includes/file.php';
1061 - \WP_Filesystem();
1062 - $content = json_decode( $wp_filesystem->get_contents( $license_file ) );
1063 - if ( ! is_object( $content ) ) {
1064 - return false;
1065 - }
1066 - if ( ! isset( $content->key ) ) {
1067 - return false;
1068 - }
1069 -
1070 - return $content->key;
1071 - }
1072 -
1073 - /**
1074 - * Run license activation on plugin activate.
1075 - */
1076 - public function auto_activate() {
1077 - $status = $this->get_license_status();
1078 - if ( 'not_active' !== $status ) {
1079 - return false;
1080 - }
1081 -
1082 - if ( ! empty( $this->namespace ) ) {
1083 - $license_key = apply_filters( 'product_' . $this->namespace . '_license_key_constant', '' );
1084 - }
1085 -
1086 - if ( empty( $license_key ) ) {
1087 - $license_key = $this->get_file_license();
1088 - }
1089 - if ( empty( $license_key ) ) {
1090 - return;
1091 - }
1092 -
1093 -
1094 - $this->license_local = $license_key;
1095 - $lock_key = $this->product->get_key() . '_autoactivated';
1096 -
1097 - if ( 'yes' === get_option( $lock_key, '' ) ) {
1098 - return;
1099 - }
1100 - if ( 'yes' === get_transient( $lock_key ) ) {
1101 - return;
1102 - }
1103 - $response = $this->do_license_process( $license_key, 'activate' );
1104 -
1105 - set_transient( $lock_key, 'yes', 6 * HOUR_IN_SECONDS );
1106 -
1107 - if ( apply_filters( $this->product->get_key() . '_hide_license_notices', false ) ) {
1108 - return;
1109 - }
1110 -
1111 - if ( true === $response ) {
1112 - add_action( 'admin_notices', [ $this, 'autoactivate_notice' ] );
1113 - }
1114 - }
1115 -
1116 - /**
1117 - * Show auto-activate notice.
1118 - */
1119 - public function autoactivate_notice() {
1120 - ?>
1121 - <div class="notice notice-success is-dismissible">
1122 - <p><?php echo sprintf( esc_html( Loader::$labels['licenser']['autoactivate_notice'] ), '<strong>' . esc_attr( $this->product->get_name() ) . '</strong>', '<strong>' . esc_attr( str_repeat( '*', 20 ) . substr( $this->license_local, - 10 ) ) . '</strong>' ); ?></p>
1123 - </div>
1124 - <?php
1125 - }
1126 -
1127 - /**
1128 - * Activate product license on this site.
1129 - *
1130 - * ## OPTIONS
1131 - *
1132 - * @param array $args Command args.
1133 - *
1134 - * [<license-key>]
1135 - * : Product license key.
1136 - */
1137 - public function cli_activate( $args ) {
1138 - $license_key = isset( $args[0] ) ? trim( $args[0] ) : '';
1139 - $response = $this->do_license_process( $license_key, 'activate' );
1140 - if ( true !== $response ) {
1141 - \WP_CLI::error( $response->get_error_message() );
1142 -
1143 - return;
1144 - }
1145 -
1146 - \WP_CLI::success( 'Product successfully activated.' );
1147 - }
1148 -
1149 - /**
1150 - * Deactivate product license on this site.
1151 - *
1152 - * @param array $args Command args.
1153 - *
1154 - * ## OPTIONS
1155 - *
1156 - * [<license-key>]
1157 - * : Product license key.
1158 - */
1159 - public function cli_deactivate( $args ) {
1160 - $license_key = isset( $args[0] ) ? trim( $args[0] ) : '';
1161 - $response = $this->do_license_process( $license_key, 'deactivate' );
1162 - if ( true !== $response ) {
1163 - \WP_CLI::error( $response->get_error_message() );
1164 -
1165 - return;
1166 - }
1167 -
1168 - \WP_CLI::success( 'Product successfully deactivated.' );
1169 - }
1170 -
1171 - /**
1172 - * Checks if product has license activated.
1173 - *
1174 - * @param array $args Command args.
1175 - *
1176 - * @subcommand is-active
1177 - */
1178 - public function cli_is_active( $args ) {
1179 -
1180 - $status = $this->get_license_status();
1181 - if ( 'valid' === $status ) {
1182 - \WP_CLI::halt( 0 );
1183 -
1184 - return;
1185 - }
1186 -
1187 - \WP_CLI::halt( 1 );
1188 718 }
1189 719 }