Skip to content

Instantly share code, notes, and snippets.

@mecha
Last active November 8, 2020 13:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mecha/eb44829106cefca6da269f855ebbe7bc to your computer and use it in GitHub Desktop.
Save mecha/eb44829106cefca6da269f855ebbe7bc to your computer and use it in GitHub Desktop.
Freemius - Free plugin updates blocked if premium and free versions do not match
<?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