Last active
August 29, 2015 14:02
-
-
Save devinsays/de040bc04ac54383d7e5 to your computer and use it in GitHub Desktop.
Allow "Package" downloads. Multiple file downloads using the same license.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* This code requires one additional filter param to be added to edd_sl_license_response in EDD_Software_Licensing.php: | |
* $response = apply_filters( 'edd_sl_license_response', $params, $download, $data) | |
*/ | |
/** | |
* Allows EDD to bypass the name check for files | |
*/ | |
define( 'EDD_BYPASS_NAME_CHECK', true ); | |
/** | |
* This allows for automatic updates if there is a single | |
* product with multiple files that also have their own seperate single downloads. | |
*/ | |
function custom_edd_sl_license_response( $response, $download, $data ) { | |
$item_name = isset( $data['item_name'] ) ? sanitize_text_field( rawurldecode( $data['item_name'] ) ) : false; | |
// Check if the license is tied to the product titled "Theme Package" | |
if ( 'Theme Package' == $download->post_title ) { | |
$switch = get_page_by_title( $item_name, 'OBJECT', 'download' ); | |
// Fire up the EDD Software Licensing Class | |
$SL = new EDD_Software_Licensing(); | |
$file = $SL->get_encoded_download_package_url( $switch->ID ); | |
$description = ! empty( $switch->post_excerpt ) ? $switch->post_excerpt : $switch->post_content; | |
$changelog = get_post_meta( $switch->ID, '_edd_sl_changelog', true ); | |
// Alter JSON response | |
$response['new_version'] = $SL->get_download_version( $switch->ID ); | |
$response['url'] = add_query_arg( 'changelog', '1', get_permalink( $switch->ID ) ); | |
$response['homepage'] = get_permalink( $switch->ID ); | |
$response['package'] = $file; | |
$response['download_link'] = $file; | |
$response['sections'] = serialize( array( | |
'description' => wpautop( strip_tags( $description, '<p><li><ul><ol><strong><a><em><span><br>' ) ), | |
'changelog' => wpautop( strip_tags( stripslashes( $changelog ), '<p><li><ul><ol><strong><a><em><span><br>' ) ) | |
) ); | |
} | |
return $response; | |
} | |
add_filter( 'edd_sl_license_response', 'custom_edd_sl_license_response', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment