Skip to content

Instantly share code, notes, and snippets.

@litonarefin
Forked from thefrosty/freemius.php
Last active July 14, 2025 00:15
Show Gist options
  • Save litonarefin/0fc7ff435744a1dee1cf7faed746b653 to your computer and use it in GitHub Desktop.
Save litonarefin/0fc7ff435744a1dee1cf7faed746b653 to your computer and use it in GitHub Desktop.
Create an override function, as to bypass Freemius in some less than smart plugins.
<?php
// REQUIRED: Make sure to edit the last few lines to assign the global variable that any particular Freemius/FS-enabled plugin wants to use to have this intercept it (if not already included below.)
// Please, any revisions for **adding more plugin to be supported by default** and/or better accommodating things are welcome at: https://gist.github.com/KZeni/7afbd8b9a94c23aa0a9133d4ce767d0b
// One would like to think this could grow to automatically intercept all plugins trying to use Freemius, but manual editing & updating a gist (maybe eventually getting to the point of being a plugin with automatic updates [be it via a WP.org plugin listing, its own built-in updater like PUM, GitHub repo where sites have plugins check a repo for new releases, etc.])
// Based on: https://gist.github.com/thefrosty/d9bb001c05a407ba1aaa60c8b75aeb43 (via https://austin.passy.co/2024/disable-freemius-in-wordpress-plugins/)
declare(strict_types=1);
/**
* Create an override function, as to bypass Freemius in stupid plugins.
* @wordpress-muplugin
* Plugin Name: Freemius Killer
* Description: Global override for Freemius' "loader".
* Version: 1.1.0
* Author: Liton Arefin
* Author URI: https://github.com/thefrosty
* phpcs:disable
*/
if (!\is_blog_installed()) {
return;
}
// Create the Freemius Stub in case other plugins use their own global we need to override.
global $freemius_stub;
$freemius_stub = new class {
// Used to generate methods missing in this Stub dynamically.
public function __call($name, $arguments)
{
return;
}
public function add_action(
$tag,
$function_to_add,
$priority = 10,
$accepted_args = 1
) {
return; // Skip
}
public function add_filter(
$hook_name,
$callback,
$priority = 10,
$accepted_args = 1
) {
return; // Skip
}
public function can_use_premium_code()
{
return false; // Don't try to use Premium code that's gated by Freemius when we're trying to not use Freemius to any capacity
}
public function can_use_premium_code__premium_only()
{
return false; // Don't try to use Premium code (especially when it's double-checking only for those that are premium, it seems?) that's gated by Freemius when we're trying to not use Freemius to any capacity
}
public function has_active_valid_license( $check_expiration = true ) {
return true;
}
public function is_activation_mode()
{
return false; // It shouldn't ever think it's doing the Freemius activation
}
public function is_activation_page()
{
return false; // It shouldn't ever think it's on the Freemius activation page
}
public function is_free_plan()
{
return true; // As an inverse of the premium code checks, let it assume it's on the free plan via Freemius
}
public function override_i18n()
{
return; // Skip
}
};
/**
* Find your plugins' Freemius global variable and assign it below.
* This example is using Menu Image; $mi_fs found in `wp-content/plugins/menu-image/menu-image.php:147`
*/
global $mi_fs;
$mi_fs = $freemius_stub;
// Post Snippets
global $postsnippets_fs;
$postsnippets_fs = $freemius_stub;
// TablePress
global $tb_tp_fs;
$tb_tp_fs = $freemius_stub;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment