Skip to content

Instantly share code, notes, and snippets.

@verygoodplugins
Created February 9, 2023 13:25
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 verygoodplugins/c06893f97c06aaa937b33c511fa5fe53 to your computer and use it in GitHub Desktop.
Save verygoodplugins/c06893f97c06aaa937b33c511fa5fe53 to your computer and use it in GitHub Desktop.
Allow active licenses to get updates if they're not at the limit, no matter what.
<?php
/**
* Allow active licenses to get updates if they're not at the limit, no matter what.
*
* @param bool $is_active Whether the site is active or not.
* @param int $license_id The license ID.
* @param string $passed_site_url The site URL.
*
* @return bool Whether the site is active or not.
*/
function wpf_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.
}
$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;
}
$site = trailingslashit( edd_software_licensing()->clean_site_url( $passed_site_url ) );
$args = array(
'site_name' => $site,
'license_id' => $license_id,
'activated' => 0,
'fields' => 'site_id',
);
$exists = edd_software_licensing()->activations_db->get_activations( $args );
if ( $exists ) {
// If the site has already been deactivated, don't re-activate it.
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;
}
add_filter( 'edd_sl_is_site_active', 'wpf_is_site_active_auto_activate_site', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment