diff --git a/groq-ai-product-text.php b/groq-ai-product-text.php index 724e240..08aa283 100644 --- a/groq-ai-product-text.php +++ b/groq-ai-product-text.php @@ -2,7 +2,7 @@ /** * Plugin Name: SitiAI Product Teksten * Description: Genereer productteksten met diverse AI-aanbieders rechtstreeks vanuit WooCommerce. - * Version: 1.9.3 + * Version: 1.9.4 * Author: Roberto Guagliardo | SitiWeb * Author URI: https://sitiweb.nl/ * Text Domain: siti-ai-product-content-generator diff --git a/includes/SitiLicenseValidator.php b/includes/SitiLicenseValidator.php index 618f57d..baadd8f 100644 --- a/includes/SitiLicenseValidator.php +++ b/includes/SitiLicenseValidator.php @@ -79,22 +79,30 @@ class SitiLicenseValidator { $code = wp_remote_retrieve_response_code( $response ); $body = json_decode( wp_remote_retrieve_body( $response ), true ); + if ( ! is_array( $body ) ) { + return new WP_Error( 'verification_failed', 'Onverwacht antwoord van licentieserver.' ); + } + + $has_payload = isset( $body['license'] ) || isset( $body['pluginVersion'] ) || isset( $body['version'] ); + if ( 200 !== $code ) { + if ( $has_payload ) { + $this->store_license_payload( $body ); + } + $error_message = isset( $body['error'] ) ? $body['error'] : 'Licentie verificatie mislukt.'; return new WP_Error( 'verification_failed', $error_message ); } if ( empty( $body['valid'] ) ) { + if ( $has_payload ) { + $this->store_license_payload( $body ); + } + return new WP_Error( 'invalid_license', 'Licentie is ongeldig.' ); } - // Update last check time - update_option( 'siti_license_last_check', current_time( 'mysql' ) ); - - // Store license data - if ( isset( $body['license'] ) ) { - update_option( 'siti_license_data', $body['license'] ); - } + $this->store_license_payload( $body ); return $body; } @@ -137,4 +145,37 @@ class SitiLicenseValidator { // In practice, you might want to proxy this through WordPress return $this->api_base_url . '/api/licenses/download?key=' . urlencode( $this->license_key ) . '&hostname=' . urlencode( $this->hostname ) . '&version=' . urlencode( $version ); } + + /** + * Persist payload data locally for UI purposes + */ + private function store_license_payload( $body ) { + $license_data = array(); + + if ( isset( $body['license'] ) && is_array( $body['license'] ) ) { + $license_data = $body['license']; + } + + if ( empty( $license_data['key'] ) ) { + $license_data['key'] = $this->license_key; + } + + $version = null; + if ( ! empty( $body['pluginVersion'] ) ) { + $version = $body['pluginVersion']; + } elseif ( ! empty( $body['version'] ) ) { + $version = $body['version']; + } + + if ( $version ) { + $license_data['pluginVersion'] = $version; + } + + if ( empty( $license_data ) ) { + return; + } + + update_option( 'siti_license_data', $license_data ); + update_option( 'siti_license_last_check', current_time( 'mysql' ) ); + } } diff --git a/includes/SitiWebUpdater2.php b/includes/SitiWebUpdater2.php index 7bd679a..b9cb708 100644 --- a/includes/SitiWebUpdater2.php +++ b/includes/SitiWebUpdater2.php @@ -273,14 +273,26 @@ class SitiWebUpdater2 { return new WP_Error( 'verification_failed', 'Onverwacht antwoord van licentieserver.' ); } + $has_license_payload = isset( $body['license'] ) || isset( $body['pluginVersion'] ) || isset( $body['version'] ); + if ( 200 !== $code ) { + if ( $has_license_payload ) { + $this->store_license_data( $body ); + } else { + $this->clear_cached_license_data(); + } + $error_message = isset( $body['error'] ) ? $body['error'] : 'Licentie verificatie mislukt.'; - $this->clear_cached_license_data(); return new WP_Error( 'verification_failed', $error_message ); } if ( empty( $body['valid'] ) ) { - $this->clear_cached_license_data(); + if ( $has_license_payload ) { + $this->store_license_data( $body ); + } else { + $this->clear_cached_license_data(); + } + return new WP_Error( 'invalid_license', 'Licentie is ongeldig.' ); }