false, 'message' => 'Invalid API endpoint' ]; } $response = wp_remote_post($api_url, [ 'method' => 'POST', 'headers' => ['Content-Type' => 'application/json'], 'body' => stripslashes(wp_json_encode($data)), 'timeout' => 20, ]); if (is_wp_error($response)) { return [ 'success' => false, 'message' => 'API Error: ' . $response->get_error_message() ]; } $body = wp_remote_retrieve_body($response); $decoded = json_decode($body, true); // A valid license always returns status_code = 200 if (isset($decoded['status_code']) && $decoded['status_code'] === 200) { return [ 'success' => true, 'message' => 'License verified', 'data' => $decoded ]; } return [ 'success' => false, 'message' => $decoded['message'] ?? 'License invalid' ]; } /** * Validate the existing license key stored in DB. * Decrypts the key and calls the external API. * * @return array License API response (same format as send_to_external_api) */ public static function validate_existing_license() { global $wpdb; $license_row = $wpdb->get_row("SELECT * FROM {$wpdb->prefix}ai_app_onsite_license_settings", ARRAY_A); if (!$license_row || empty($license_row['license_key'])) { return [ 'success' => false, 'message' => 'No license key found' ]; } $data = [ 'access_key' => self::decrypt_string($license_row['license_key']), 'domain' => $_SERVER['HTTP_HOST'] ]; return self::send_to_external_api($data); } }