Skip to content

Instantly share code, notes, and snippets.

@danieliser
Forked from zackkatz/eddsl-auto-activate.php
Created October 21, 2020 20:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danieliser/da3f8a05bc6b634e71483d2ac898280b to your computer and use it in GitHub Desktop.
Save danieliser/da3f8a05bc6b634e71483d2ac898280b to your computer and use it in GitHub Desktop.
Auto-activate sites on Easy Digital Downloads Software Licensing
<?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