/**
  * Unlicense a site.
  *
  * @param string $siteUrl
  * @param string $licenseKey
  * @param string $token
  * @return Wslm_ProductLicense|WP_Error|null
  */
 public function unlicenseSite($siteUrl, $licenseKey, $token = null)
 {
     if (!empty($licenseKey)) {
         $apiResponse = $this->api->unlicenseSite($this->productSlug, $licenseKey, $siteUrl);
     } else {
         if (!empty($token)) {
             $apiResponse = $this->api->unlicenseSiteByToken($this->getProductSlug(), $token, $siteUrl);
         } else {
             return new WP_Error('invalid_argument', 'To unlicense a site, you must specify either a license key or a site token.');
         }
     }
     $responseLicense = null;
     if (isset($apiResponse->response->license)) {
         $responseLicense = $this->createLicenseObject($apiResponse->response->license);
     }
     if ($apiResponse->success()) {
         $result = $responseLicense;
     } else {
         $error = $apiResponse->asWpError();
         if (isset($responseLicense)) {
             $error->add_data('license', $responseLicense);
         }
         $result = $error;
     }
     //Did we just remove the license from the current site?
     if ($siteUrl === $this->getSiteUrl()) {
         if (!is_wp_error($result) || $result->get_error_code() !== 'api_request_failed') {
             //Success. Or, if the request fails for any reason other than API problems,
             //chances are the stored license was invalid. So we'll remove the local copy anyway.
             $this->resetState();
         }
     }
     return $result;
 }