Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mklasen/85b4e5f4934db6d6a47f05da4244b630 to your computer and use it in GitHub Desktop.
Save mklasen/85b4e5f4934db6d6a47f05da4244b630 to your computer and use it in GitHub Desktop.
EDD: Enable software updates for free downloads
<?php
class Enable_Software_Updates_For_Free_Downloads {
public function __construct() {
$this->hooks();
}
public function hooks() {
add_filter( 'edd_sl_generate_license_key', array( $this, 'generate_free_license_key' ), 10, 5 );
add_filter( 'edd_sl_check_license_status', array( $this, 'skip_free_download_license_check' ), 10, 2 );
}
/**
* When generating a free license, set the key.
*/
public function generate_free_license_key( $key, $license_id, $download_id, $payment_id, $cart_index ) {
if ( edd_is_free_download( $download_id ) ) {
$key = 'free-download';
}
return $key;
}
/**
* Mark license as valid when it's a free download. (since it's never activated)
*/
public function skip_free_download_license_check( $status, $license ) {
if ( $license->__get( 'key' ) === 'free-download' ) {
$status = 'valid';
}
return $status;
}
}
<?php
$edd_updater = new EDD_SL_Plugin_Updater( $this->_store_url, __FILE__, array(
'version' => $this->_version,
'license' => 'free-download',
'item_id' => $this->_item_id,
'author' => 'Sympose',
'url' => home_url(),
'beta' => false
) );
@SiteSpot
Copy link

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment