Skip to content

Instantly share code, notes, and snippets.

@shazahm1
Last active August 29, 2015 13:57
Show Gist options
  • Save shazahm1/9652515 to your computer and use it in GitHub Desktop.
Save shazahm1/9652515 to your computer and use it in GitHub Desktop.
EDD SL filter to add the checkout uri to the remote license check response.
<?php
/**
* Add the renewal checkout URL to the remote license check response.
*
* @param array $response The response array.
* @param array $atts The atts for EDD_Software_Licensing::remote_license_check()
* @param string $license_id The license key.
* @return array The response array.
*/
function cn_remote_license_check_response( $response, $atts, $license_id ) {
// Ensure the required functions exist; if not return $response.
if ( ! function_exists( 'edd_sl_renewals_allowed' ) &&
! function_exists( 'edd_software_licensing' ) &&
! function_exists( 'edd_get_checkout_uri' ) ) {
return $response;
}
// Ensure the license key exists; if not return $response.
if ( ! isset( $atts['key'] ) || empty( $atts['key'] ) ) {
return $response;
}
// If license renewl is not permitted; return $response.
if ( ! edd_sl_renewals_allowed() ) {
return $response;
}
// No need to add the checkout URI to the responcse if the license is not expired.
if ( $response['license'] !== 'expired' ) {
return $response;
}
// Bring into scope the EDD SL Class.
$licensing = edd_software_licensing();
// Get the download ID from the license key.
$download_id = $licensing->get_download_by_license( $atts['key'] );
// If the download ID was found, add the renewal URI to $response.
if ( $download_id !== FALSE ) {
$response['renewal_url'] = edd_get_checkout_uri( array( 'edd_license_key' => $atts['key'], 'download_id' => $download_id ) );
}
return $response;
}
add_filter( 'edd_remote_license_check_response', 'cn_remote_license_check_response', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment