-
-
Save vovafeldman/4262b5f398c6f379ae547efbaad9e458 to your computer and use it in GitHub Desktop.
Freemius - Free plugin updates blocked if premium and free versions do not match
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 | |
// Functions that you'll need | |
function get_free_version() { /* ... */ } | |
function get_premium_version() { /* ... */ } | |
function is_free_plugin($plugin_basename) { /* ... */ } | |
// Filter the value of the transient where WordPress stores pending updates | |
add_filter('site_transient_update_plugins', function ($value) { | |
// Only proceed if the transient has responses from update servers | |
if (is_object($value) && !empty($value->response)) { | |
$f_ver = get_free_version(); | |
$p_ver = get_premium_version(); | |
// If the free version is older than the premium version ... | |
if (version_compare($f_ver, $p_ver, '<')) { | |
// Strip out all entries for the free version from the response array | |
$value->response = array_filter($value->response ?? [], function ($response) { | |
return !is_free_plugin($response->plugin); | |
}); | |
} | |
} | |
return $value; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment