ActivationForm.php
4 years ago
CheckForm.php
4 years ago
Endpoint.php
4 years ago
License.php
4 years ago
RequestResponse.php
4 years ago
Updater.php
4 years ago
CheckForm.php
46 lines
| 1 | <?php |
| 2 | namespace Kubio\Core\License; |
| 3 | |
| 4 | class CheckForm { |
| 5 | |
| 6 | public function __construct() { |
| 7 | add_action( 'wp_ajax_kubiowp-page-builder-check-license', array( $this, 'callCheckLicenseEndpoint' ) ); |
| 8 | } |
| 9 | |
| 10 | public function printForm() { |
| 11 | wp_enqueue_script( 'wp-util' ); |
| 12 | add_action( 'admin_notices', array( $this, 'makeNotice' ) ); |
| 13 | } |
| 14 | |
| 15 | public function makeNotice() { |
| 16 | License::getInstance()->getActivationForm()->makeActivateNotice( 'kubio-page-builder-check-license', array( 'hidden' ) ); |
| 17 | } |
| 18 | |
| 19 | public function callCheckLicenseEndpoint() { |
| 20 | $response = Endpoint::check(); |
| 21 | $response_message = $response->getMessage( true ); |
| 22 | |
| 23 | if ( $response->isWPError() ) { |
| 24 | $url = esc_attr( License::getInstance()->getDashboardUrl() ); |
| 25 | $response_message = sprintf( __( 'There was an error calling Kubio License Server: <code>%1$s</code>. Please contact us for support on <a href="%2$s" target="_blank">Kubio</a> website', 'kubio' ), $response_message, $url ); |
| 26 | } |
| 27 | |
| 28 | if ( $response->isSuccess() ) { |
| 29 | License::getInstance()->touch(); |
| 30 | } else { |
| 31 | if ( ! $response->isWPError() && $response->getResponseCode() === 403 ) { |
| 32 | delete_option( 'kubiowp_builder_license_key' ); |
| 33 | $response_message = sprintf( __( 'Current license key was removed! Reason: %s', 'kubio' ), $response_message ); |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | wp_send_json( |
| 38 | array( |
| 39 | 'data' => $response_message, |
| 40 | 'success' => $response->isSuccess(), |
| 41 | ), |
| 42 | $response->getResponseCode() |
| 43 | ); |
| 44 | } |
| 45 | } |
| 46 |