Forked from zackkatz/eddsl-auto-activate.php
Created
October 21, 2020 20:22
Star
You must be signed in to star a gist
Auto-activate sites on Easy Digital Downloads Software Licensing
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
<?php | |
add_filter( 'edd_sl_is_site_active', 'your_namespace_is_site_active_auto_activate_site', 10, 3 ); | |
/** | |
* Allow active licenses to get updates if they're not at the limit, no matter what. | |
* | |
* @param false $is_active | |
* @param int $license_id | |
* @param string $passed_site_url | |
* | |
* @return bool | |
*/ | |
function your_namespace_is_site_active_auto_activate_site( $is_active = false, $license_id = 0, $passed_site_url = '' ) { | |
if( true === $is_active ) { | |
return true; // Already passed the check | |
} | |
if ( ! wp_http_validate_url( $passed_site_url ) ) { | |
return $is_active; // Can't add invalid URLs to the license anyway, return early | |
} | |
$license = edd_software_licensing()->get_license( $license_id ); | |
// Only allow active licenses to get updates if they're not at the limit | |
if( ! $license || ! $license->is_at_limit() || 'active' !== $license->status ) { | |
return $is_active; | |
} | |
// And then add the site | |
$license->add_site( $passed_site_url ); | |
// And enter this activation in the log | |
edd_software_licensing()->log_license_activation( $license->ID, $_SERVER ); | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment