PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.4.0
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.4.0
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
visualizer / vendor / codeinwp / themeisle-sdk / src / Modules / Licenser.php

Licenser.php in Visualizer – Tables & Charts Manager with Built-in AI Generator 3.4.0, at vendor/codeinwp/themeisle-sdk/src/Modules/Licenser.php

799 lines 22.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * The main loader class for license handling.
4 *
5 * @package ThemeIsleSDK
6 * @subpackage Modules
7 * @copyright Copyright (c) 2017, Marius Cristea
8 * @license http://opensource.org/licenses/gpl-3.0.php GNU Public License
9 * @since 1.0.0
10 */
11
12 namespace ThemeisleSDK\Modules;
13
14 // Exit if accessed directly.
15 use ThemeisleSDK\Common\Abstract_Module;
16 use ThemeisleSDK\Product;
17
18 if ( ! defined( 'ABSPATH' ) ) {
19 exit;
20 }
21
22 /**
23 * Licenser module for ThemeIsle SDK.
24 */
25 class Licenser extends Abstract_Module {
26
27 /**
28 * Number of max failed checks before showing the license message.
29 *
30 * @var int $max_failed Maximum failed checks allowed before show the notice
31 */
32 private static $max_failed = 5;
33 /**
34 * License key string.
35 *
36 * @var string $license_key The license key string
37 */
38 public $license_key;
39 /**
40 * This ensures that the custom API request only runs on the second time that WP fires the update check.
41 *
42 * @var bool $do_check Flag for request.
43 */
44 private $do_check = false;
45 /**
46 * Number of failed checks to the api endpoint.
47 *
48 * @var bool $failed_checks
49 */
50 private $failed_checks = 0;
51 /**
52 * The product update response key.
53 *
54 * @var string $product_key Product key.
55 */
56 private $product_key;
57
58 /**
59 * Disable wporg updates for premium products.
60 *
61 * @param string $r Update payload.
62 * @param string $url The api url.
63 *
64 * @return mixed List of themes to check for update.
65 */
66 function disable_wporg_update( $r, $url ) {
67
68 if ( 0 !== strpos( $url, 'https://api.wordpress.org/themes/update-check/' ) ) {
69 return $r;
70 }
71
72 // Decode the JSON response.
73 $themes = json_decode( $r['body']['themes'] );
74
75 unset( $themes->themes->{$this->product->get_slug()} );
76
77 // Encode the updated JSON response.
78 $r['body']['themes'] = json_encode( $themes );
79
80 return $r;
81 }
82
83 /**
84 * Register the setting for the license of the product.
85 *
86 * @return bool
87 */
88 public function register_settings() {
89 if ( ! is_admin() ) {
90 return false;
91 }
92 if ( apply_filters( $this->product->get_key() . '_hide_license_field', false ) ) {
93 return;
94 }
95 add_settings_field(
96 $this->product->get_key() . '_license',
97 $this->product->get_name() . ' license',
98 array( $this, 'license_view' ),
99 'general'
100 );
101 }
102
103 /**
104 * The license view field.
105 */
106 public function license_view() {
107 $status = $this->get_license_status();
108 $value = $this->license_key;
109
110 $activate_string = apply_filters( $this->product->get_key() . '_lc_activate_string', 'Activate' );
111 $deactivate_string = apply_filters( $this->product->get_key() . '_lc_deactivate_string', 'Deactivate' );
112 $valid_string = apply_filters( $this->product->get_key() . '_lc_valid_string', 'Valid' );
113 $invalid_string = apply_filters( $this->product->get_key() . '_lc_invalid_string', 'Invalid' );
114 $license_message = apply_filters( $this->product->get_key() . '_lc_license_message', 'Enter your license from %s purchase history in order to get %s updates' );
115 $error_message = $this->get_error();
116 ?>
117 <style type="text/css">
118 input.themeisle-sdk-text-input-valid {
119 border: 1px solid #7ad03a;
120 }
121
122 input.themeisle-sdk-license-input {
123 width: 300px;
124 padding: 0 8px;
125 line-height: 2;
126 min-height: 30px;
127 }
128
129 .themeisle-sdk-license-deactivate-cta {
130 color: #fff;
131 background: #7ad03a;
132 display: inline-block;
133 text-decoration: none;
134 font-size: 13px;
135 line-height: 30px;
136 height: 26px;
137 margin-left: 5px;
138 padding: 0 10px 3px;
139 -webkit-border-radius: 3px;
140 border-radius: 3px;
141 }
142
143 .themeisle-sdk-license-activate-cta {
144 color: #fff;
145 background: #dd3d36;
146 display: inline-block;
147 text-decoration: none;
148 font-size: 13px;
149 line-height: 30px;
150 height: 26px;
151 margin-left: 5px;
152 padding: 0 10px 3px;
153 -webkit-border-radius: 3px;
154 border-radius: 3px;
155 }
156
157 button.button.themeisle-sdk-licenser-button-cta {
158 line-height: 26px;
159 height: 29px;
160 vertical-align: top;
161 }
162
163 </style>
164 <?php
165 echo sprintf(
166 '<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',
167 ( ( 'valid' === $status ) ? sprintf( '<input type="hidden" value="%s" name="%s_license" />', $value, $this->product->get_key() ) : '' ),
168 ( ( 'valid' === $status ) ? 'themeisle-sdk-text-input-valid' : '' ),
169 $this->product->get_key(),
170 ( ( 'valid' === $status ) ? $this->product->get_key() . '_mask' : $this->product->get_key() ),
171 ( ( 'valid' === $status ) ? ( str_repeat( '*', 30 ) . substr( $value, - 5 ) ) : $value ),
172 ( 'valid' === $status ? 'themeisle-sdk-license-deactivate-cta' : 'themeisle-sdk-license-activate-cta' ),
173 ( 'valid' === $status ? $valid_string : $invalid_string ),
174 $this->product->get_key(),
175 ( 'valid' === $status ? $deactivate_string : $activate_string ),
176 sprintf( $license_message, '<a href="' . $this->get_api_url() . '">' . $this->get_distributor_name() . '</a> ', $this->product->get_type() ),
177 empty( $error_message ) ? '' : sprintf( '<p style="color:#dd3d36">%s</p>', $error_message )
178 );
179
180 }
181
182 /**
183 * Return the license status.
184 *
185 * @return string The License status.
186 */
187 public function get_license_status() {
188
189 $license_data = get_option( $this->product->get_key() . '_license_data', '' );
190
191 if ( '' === $license_data ) {
192 return get_option( $this->product->get_key() . '_license_status', 'not_active' );
193 }
194
195 return isset( $license_data->license ) ? $license_data->license : get_option( $this->product->get_key() . '_license_status', 'not_active' );
196
197 }
198
199 /**
200 * Get remote api url.
201 *
202 * @return string Remote api url.
203 */
204 public function get_api_url() {
205 if ( $this->is_from_partner( $this->product ) ) {
206 return 'https://themeisle.com';
207 }
208
209 return $this->product->get_store_url();
210 }
211
212 /**
213 * Get remote api url.
214 *
215 * @return string Remote api url.
216 */
217 public function get_distributor_name() {
218 if ( $this->is_from_partner( $this->product ) ) {
219 return 'ThemeIsle';
220 }
221
222 return $this->product->get_store_name();
223 }
224
225 /**
226 * Show the admin notice regarding the license status.
227 *
228 * @return bool Should we show the notice ?
229 */
230 function show_notice() {
231 if ( ! is_admin() ) {
232 return false;
233 }
234
235 if ( apply_filters( $this->product->get_key() . '_hide_license_notices', false ) ) {
236 return;
237 }
238 $status = $this->get_license_status();
239 $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.' );
240 $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>. ' );
241
242 // No activations left for this license.
243 if ( 'valid' != $status && $this->check_activation() ) {
244 ?>
245 <div class="error">
246 <p><strong>
247 <?php
248 echo sprintf(
249 $no_activations_string,
250 $this->product->get_name(),
251 $this->product->get_name(),
252 '<a href="' . $this->get_api_url() . '" target="_blank">' . $this->get_distributor_name() . '</a>'
253 );
254 ?>
255 </strong>
256 </p>
257 </div>
258 <?php
259 return false;
260 }
261 // Invalid license key.
262 if ( 'valid' != $status ) {
263 ?>
264 <div class="error">
265 <p>
266 <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() . '_license' ); ?> </strong>
267 </p>
268 </div>
269 <?php
270
271 return false;
272 }
273
274 return true;
275 }
276
277 /**
278 * Check if the license is active or not.
279 *
280 * @return bool
281 */
282 public function check_activation() {
283 $license_data = get_option( $this->product->get_key() . '_license_data', '' );
284 if ( '' === $license_data ) {
285 return false;
286 }
287
288 return isset( $license_data->error ) ? ( 'no_activations_left' == $license_data->error ) : false;
289
290 }
291
292 /**
293 * Check if the license is about to expire in the next month.
294 *
295 * @return bool
296 */
297 function check_expiration() {
298 $license_data = get_option( $this->product->get_key() . '_license_data', '' );
299 if ( '' === $license_data ) {
300 return false;
301 }
302 if ( ! isset( $license_data->expires ) ) {
303 return false;
304 }
305 if ( strtotime( $license_data->expires ) - time() > 30 * 24 * 3600 ) {
306 return false;
307 }
308
309 return true;
310 }
311
312 /**
313 * Return the renew url from the store used.
314 *
315 * @return string The renew url.
316 */
317 function renew_url() {
318 $license_data = get_option( $this->product->get_key() . '_license_data', '' );
319 if ( '' === $license_data ) {
320 return $this->get_api_url();
321 }
322 if ( ! isset( $license_data->download_id ) || ! isset( $license_data->key ) ) {
323 return $this->get_api_url();
324 }
325
326 return $this->get_api_url() . '/checkout/?edd_license_key=' . $license_data->key . '&download_id=' . $license_data->download_id;
327 }
328
329 /**
330 * Run the license check call.
331 */
332 public function product_valid() {
333 if ( false !== ( $license = get_transient( $this->product->get_key() . '_license_data' ) ) ) {
334 return;
335 }
336 $license = $this->check_license();
337 set_transient( $this->product->get_key() . '_license_data', $license, 12 * HOUR_IN_SECONDS );
338 update_option( $this->product->get_key() . '_license_data', $license );
339 }
340
341 /**
342 * Check the license status.
343 *
344 * @return object The license data.
345 */
346 public function check_license() {
347 $status = $this->get_license_status();
348 if ( 'not_active' == $status ) {
349 $license_data = new \stdClass();
350 $license_data->license = 'not_active';
351
352 return $license_data;
353 }
354 $license = trim( $this->license_key );
355 $api_params = array(
356 'edd_action' => 'check_license',
357 'license' => $license,
358 'item_name' => rawurlencode( $this->product->get_name() ),
359 'url' => rawurlencode( home_url() ),
360 );
361 // Call the custom API.
362 $response = wp_remote_get(
363 add_query_arg( $api_params, $this->get_api_url() ),
364 array(
365 'timeout' => 15,
366 'sslverify' => false,
367 )
368 );
369 if ( is_wp_error( $response ) ) {
370 $license_data = new \stdClass();
371 $license_data->license = 'valid';
372
373 } else {
374 $license_data = json_decode( wp_remote_retrieve_body( $response ) );
375 if ( ! is_object( $license_data ) ) {
376 $license_data = new \stdClass();
377 $license_data->license = 'valid';
378 }
379 }
380 $license_old = get_option( $this->product->get_key() . '_license_data', '' );
381 if ( 'valid' == $license_old->license && ( $license_data->license != $license_old->license ) ) {
382 $this->increment_failed_checks();
383 } else {
384 $this->reset_failed_checks();
385 }
386
387 if ( $this->failed_checks <= self::$max_failed ) {
388 return $license_old;
389 }
390
391 if ( isset( $license_old->hide_valid ) ) {
392 $license_data->hide_valid = true;
393 }
394
395 if ( ! isset( $license_data->key ) ) {
396 $license_data->key = isset( $license_old->key ) ? $license_old->key : '';
397 }
398
399 if ( isset( $license_old->hide_expiration ) ) {
400 $license_data->hide_expiration = true;
401 }
402
403 if ( isset( $license_old->hide_activation ) ) {
404 $license_data->hide_activation = true;
405 }
406
407 return $license_data;
408
409 }
410
411 /**
412 * Increment the failed checks.
413 */
414 private function increment_failed_checks() {
415 $this->failed_checks ++;
416 update_option( $this->product->get_key() . '_failed_checks', $this->failed_checks );
417 }
418
419 /**
420 * Reset the failed checks
421 */
422 private function reset_failed_checks() {
423 $this->failed_checks = 1;
424 update_option( $this->product->get_key() . '_failed_checks', $this->failed_checks );
425 }
426
427 /**
428 * Set license validation error message.
429 *
430 * @param string $message Error message.
431 */
432 public function set_error( $message = '' ) {
433 set_transient( $this->product->get_key() . 'act_err', $message, MINUTE_IN_SECONDS );
434
435 return;
436 }
437
438 /**
439 * Return the last error message.
440 *
441 * @return mixed Error message.
442 */
443 public function get_error() {
444 return get_transient( $this->product->get_key() . 'act_err' );
445 }
446
447 /**
448 * Activate the license remotely.
449 */
450 function activate_license() {
451 // listen for our activate button to be clicked.
452 if ( ! isset( $_POST[ $this->product->get_key() . '_btn_trigger' ] ) ) {
453 return;
454 }
455 $status = $this->get_license_status();
456 // retrieve the license from the database.
457 $license = $_POST[ $this->product->get_key() . '_license' ];
458 $api_params = array(
459 'license' => $license,
460 'item_name' => rawurlencode( $this->product->get_name() ),
461 'url' => rawurlencode( home_url() ),
462 );
463 if ( 'valid' != $status ) {
464 // data to send in our API request.
465 $api_params['edd_action'] = 'activate_license';
466 } else {
467 $api_params['edd_action'] = 'deactivate_license';
468 }
469 // Call the custom API.
470 $response = wp_remote_get( add_query_arg( $api_params, $this->get_api_url() ) );
471 // make sure the response came back okay.
472 if ( is_wp_error( $response ) ) {
473 $this->set_error( sprintf( 'ERROR: Failed to connect to the license service. Please try again later. Reason: %s', $response->get_error_message() ) );
474
475 return;
476 }
477
478 $license_data = json_decode( wp_remote_retrieve_body( $response ) );
479
480 if ( ! is_object( $license_data ) ) {
481 $this->set_error( 'ERROR: Failed to validate license. Please try again in one minute.' );
482
483 return;
484 }
485 if ( ! isset( $license_data->license ) ) {
486 $license_data->license = 'invalid';
487 }
488
489 if ( ! isset( $license_data->key ) ) {
490 $license_data->key = $license;
491 }
492 if ( 'valid' == $license_data->license ) {
493 $this->reset_failed_checks();
494 }
495
496 $this->set_error( '' );
497
498 if ( 'deactivate_license' === $api_params['edd_action'] ) {
499
500 delete_option( $this->product->get_key() . '_license_data' );
501 delete_option( $this->product->get_key() . '_license_plan' );
502 delete_transient( $this->product->get_key() . '_license_data' );
503
504 return;
505 }
506 if ( isset( $license_data->plan ) ) {
507 update_option( $this->product->get_key() . '_license_plan', $license_data->plan );
508 }
509 update_option( $this->product->get_key() . '_license_data', $license_data );
510 set_transient( $this->product->get_key() . '_license_data', $license_data, 12 * HOUR_IN_SECONDS );
511
512 }
513
514 /**
515 * Load the Themes screen.
516 */
517 function load_themes_screen() {
518 add_thickbox();
519 add_action( 'admin_notices', array( &$this, 'update_nag' ) );
520 }
521
522 /**
523 * Alter the nag for themes update.
524 */
525 function update_nag() {
526 $theme = wp_get_theme( $this->product->get_slug() );
527 $api_response = get_transient( $this->product_key );
528 if ( false === $api_response || ! isset( $api_response->new_version ) ) {
529 return;
530 }
531 $update_url = wp_nonce_url( 'update.php?action=upgrade-theme&amp;theme=' . urlencode( $this->product->get_slug() ), 'upgrade-theme_' . $this->product->get_slug() );
532 $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.' );
533 $update_onclick = ' onclick="if ( confirm(\'' . esc_js( $update_message ) . '\') ) {return true;}return false;"';
534 if ( version_compare( $this->product->get_version(), $api_response->new_version, '<' ) ) {
535 echo '<div id="update-nag">';
536 printf(
537 '<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>.',
538 $theme->get( 'Name' ),
539 $api_response->new_version,
540 sprintf( '%s&TB_iframe=true&amp;width=1024&amp;height=800', $this->product->get_changelog() ),
541 $theme->get( 'Name' ),
542 $update_url,
543 $update_onclick
544 );
545 echo '</div>';
546 echo '<div id="' . $this->product->get_slug() . '_' . 'changelog" style="display:none;">';
547 echo wpautop( $api_response->sections['changelog'] );
548 echo '</div>';
549 }
550 }
551
552 /**
553 * Alter update transient.
554 *
555 * @param mixed $value The transient data.
556 *
557 * @return mixed
558 */
559 function theme_update_transient( $value ) {
560 $update_data = $this->check_for_update();
561 if ( $update_data ) {
562 $value->response[ $this->product->get_slug() ] = $update_data;
563 }
564
565 return $value;
566 }
567
568 /**
569 * Check for updates
570 *
571 * @return array|bool Either the update data or false in case of failure.
572 */
573 function check_for_update() {
574 $update_data = get_transient( $this->product_key );
575
576 if ( false === $update_data ) {
577 $failed = false;
578 $update_data = $this->get_version_data();
579 if ( empty( $update_data ) ) {
580 $failed = true;
581 }
582 // If the response failed, try again in 30 minutes.
583 if ( $failed ) {
584 $data = new \stdClass();
585 $data->new_version = $this->product->get_version();
586 set_transient( $this->product_key, $data, 30 * MINUTE_IN_SECONDS );
587
588 return false;
589 }
590 $update_data->sections = isset( $update_data->sections ) ? maybe_unserialize( $update_data->sections ) : null;
591
592 set_transient( $this->product_key, $update_data, 12 * HOUR_IN_SECONDS );
593 }
594 if ( ! isset( $update_data->new_version ) ) {
595 return false;
596 }
597 if ( version_compare( $this->product->get_version(), $update_data->new_version, '>=' ) ) {
598 return false;
599 }
600
601 return (array) $update_data;
602 }
603
604 /**
605 * Check remote api for latest version.
606 *
607 * @return bool|mixed Update api response.
608 */
609 private function get_version_data() {
610 $api_params = array(
611 'edd_action' => 'get_version',
612 'version' => $this->product->get_version(),
613 'license' => empty( $this->license_key ) ? 'free' : $this->license_key,
614 'name' => rawurlencode( $this->product->get_name() ),
615 'slug' => $this->product->get_slug(),
616 'author' => rawurlencode( $this->get_distributor_name() ),
617 'url' => rawurlencode( home_url() ),
618 );
619 $response = wp_remote_get(
620 add_query_arg( $api_params, $this->get_api_url() ),
621 array(
622 'timeout' => 15,
623 'sslverify' => false,
624 )
625 );
626 if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) ) {
627 return false;
628 }
629 $update_data = json_decode( wp_remote_retrieve_body( $response ) );
630 if ( ! is_object( $update_data ) ) {
631 return false;
632 }
633
634 return $update_data;
635 }
636
637 /**
638 * Delete the update transient
639 */
640 function delete_theme_update_transient() {
641 delete_transient( $this->product_key );
642 }
643
644 /**
645 * Check for Updates at the defined API endpoint and modify the update array.
646 *
647 * @param array $_transient_data Update array build by WordPress.
648 *
649 * @return mixed Modified update array with custom plugin data.
650 */
651 public function pre_set_site_transient_update_plugins_filter( $_transient_data ) {
652 if ( empty( $_transient_data ) || ! $this->do_check ) {
653 $this->do_check = true;
654
655 return $_transient_data;
656 }
657 $api_response = $this->api_request();
658 if ( false !== $api_response && is_object( $api_response ) && isset( $api_response->new_version ) ) {
659 if ( version_compare( $this->product->get_version(), $api_response->new_version, '<' ) ) {
660 $_transient_data->response[ $this->product->get_slug() . '/' . $this->product->get_file() ] = $api_response;
661 }
662 }
663
664 return $_transient_data;
665 }
666
667 /**
668 * Calls the API and, if successfull, returns the object delivered by the API.
669 *
670 * @param string $_action The requested action.
671 * @param array $_data Parameters for the API action.
672 *
673 * @return false||object
674 */
675 private function api_request( $_action = '', $_data = '' ) {
676 $update_data = $this->get_version_data();
677 if ( empty( $update_data ) ) {
678 return false;
679 }
680 if ( $update_data && isset( $update_data->sections ) ) {
681 $update_data->sections = maybe_unserialize( $update_data->sections );
682 }
683
684 return $update_data;
685 }
686
687 /**
688 * Updates information on the "View version x.x details" page with custom data.
689 *
690 * @param mixed $_data Plugin data.
691 * @param string $_action Action to send.
692 * @param object $_args Arguments to use.
693 *
694 * @return object $_data
695 */
696 public function plugins_api_filter( $_data, $_action = '', $_args = null ) {
697 if ( ( 'plugin_information' != $_action ) || ! isset( $_args->slug ) || ( $_args->slug != $this->product->get_slug() ) ) {
698 return $_data;
699 }
700 $api_response = $this->api_request();
701 if ( false !== $api_response ) {
702 $_data = $api_response;
703 }
704
705 return $_data;
706 }
707
708 /**
709 * Disable SSL verification in order to prevent download update failures.
710 *
711 * @param array $args Http args.
712 * @param string $url Url to check.
713 *
714 * @return array $array
715 */
716 function http_request_args( $args, $url ) {
717 // If it is an https request and we are performing a package download, disable ssl verification.
718 if ( strpos( $url, 'https://' ) !== false && strpos( $url, 'edd_action=package_download' ) ) {
719 $args['sslverify'] = false;
720 }
721
722 return $args;
723 }
724
725 /**
726 * Check if we should load the module for this product.
727 *
728 * @param Product $product Product data.
729 *
730 * @return bool Should we load the module?
731 */
732 public function can_load( $product ) {
733
734 if ( $product->is_wordpress_available() ) {
735 return false;
736 }
737
738 return ( apply_filters( $product->get_key() . '_enable_licenser', true ) === true );
739
740 }
741
742 /**
743 * Load module logic.
744 *
745 * @param Product $product Product to load the module for.
746 *
747 * @return Licenser Module object.
748 */
749 public function load( $product ) {
750 $this->product = $product;
751
752 $this->product_key = $this->product->get_key() . '-update-response';
753
754 $this->license_key = $this->product->get_license();
755 if ( $this->product->requires_license() ) {
756 $this->failed_checks = intval( get_option( $this->product->get_key() . '_failed_checks', 0 ) );
757 $this->register_license_hooks();
758 }
759
760 if ( $this->product->is_plugin() ) {
761 add_filter(
762 'pre_set_site_transient_update_plugins',
763 [
764 $this,
765 'pre_set_site_transient_update_plugins_filter',
766 ]
767 );
768 add_filter( 'plugins_api', array( $this, 'plugins_api_filter' ), 10, 3 );
769 add_filter( 'http_request_args', array( $this, 'http_request_args' ), 10, 2 );
770
771 return $this;
772 }
773 if ( $this->product->is_theme() ) {
774 add_filter( 'site_transient_update_themes', array( &$this, 'theme_update_transient' ) );
775 add_filter( 'delete_site_transient_update_themes', array( &$this, 'delete_theme_update_transient' ) );
776 add_action( 'load-update-core.php', array( &$this, 'delete_theme_update_transient' ) );
777 add_action( 'load-themes.php', array( &$this, 'delete_theme_update_transient' ) );
778 add_action( 'load-themes.php', array( &$this, 'load_themes_screen' ) );
779 add_filter( 'http_request_args', array( $this, 'disable_wporg_update' ), 5, 2 );
780
781 return $this;
782
783 }
784
785 return $this;
786 }
787
788 /**
789 * Register license fields for the products.
790 */
791 public function register_license_hooks() {
792 add_action( 'admin_init', array( $this, 'register_settings' ) );
793 add_action( 'admin_init', array( $this, 'activate_license' ) );
794 add_action( 'admin_init', array( $this, 'product_valid' ), 99999999 );
795 add_action( 'admin_notices', array( $this, 'show_notice' ) );
796 add_filter( $this->product->get_key() . '_license_status', array( $this, 'get_license_status' ) );
797 }
798 }
799