-
Notifications
You must be signed in to change notification settings - Fork 29
Indicate when the license key is valid, but the domain isn't registered for the license key #24
Comments
EDD SL actually returns a body with the 401 (Unauthorized) that is much more informative (if you copy the link and open it in your browser, you'll see). But cUrl doesn't take a body for 40X errors so it gets lost with a generic 'Unauthorized' (more about the cUrl options here) I guess one solution could be to use the Here's a somewhat more simple solution, that at least overrides the generic 'Unauthorized': add_filter( 'http_response', 'http_response_debug', 10, 3 );
function http_response_debug($response, $args, $url) {
if (isset($response['response']) && is_array($response['response'])) {
if (isset($response['response']['code']) && $response['response']['code'] == 401 ) {
// we have a 401 response, check if it's ours
$license_server = 'https://www.yoursite.com';
if (strpos($url, $license_server) !== false && strpos($url, 'package_download') !== false) {
// this is our request
// extract values from token
$url_parts = parse_url( $url );
$paths = array_values( explode( '/', $url_parts['path'] ) );
$token = end( $paths );
$values = explode( ':', base64_decode( $token ) );
if ( count( $values ) !== 6 ) {
$response['response']['message'] = __( 'Invalid token supplied', 'edd_sl' );
return $response;
}
$expires = $values[0];
$license_key = $values[1];
$download_id = (int) $values[2];
$url = str_replace( '@', ':', $values[4] );
$download_beta = (bool) $values[5];
// This could also be an actual check_license response with the above vars!
$message = __( 'License key expired or not activated for URL', 'edd_sl' );
$response['response']['message'] = $message;
return $response;
}
}
}
return $response;
} Replace |
Just adding that if you're not interested in checking the license to show a more detailed message, you can use a shorter version without all the token extraction code: add_filter( 'http_response', 'http_response_debug', 10, 3 );
function http_response_debug($response, $args, $url) {
if (isset($response['response']) && is_array($response['response'])) {
if (isset($response['response']['code']) && $response['response']['code'] == 401 ) {
// we have a 401 response, check if it's ours
$license_server = 'https://www.yoursite.com';
if (strpos($url, $license_server) !== false && strpos($url, 'package_download') !== false) {
// this is our request
$response['response']['message'] = __( 'License key expired or not activated for URL', 'edd_sl' );
return $response;
}
}
}
return $response;
} |
When a user has provided a valid license key, they'll see a prompt to update the plugin when there's a new version available.
However, if the domain isn't registered to the license key, they'll see this cryptic error when they try to update:
It would be better to intercept the user earlier so they don't try the update process and end up in this state.
Similarly, "Download Failed: Unauthorized" would be better as "Download Failed: License key expired or not activated for URL".
The text was updated successfully, but these errors were encountered: