Skip to content

Instantly share code, notes, and snippets.

@KZeni
Forked from thefrosty/freemius.php
Last active May 18, 2024 14:34
Show Gist options
  • Save KZeni/7afbd8b9a94c23aa0a9133d4ce767d0b to your computer and use it in GitHub Desktop.
Save KZeni/7afbd8b9a94c23aa0a9133d4ce767d0b to your computer and use it in GitHub Desktop.
Freemius Killer: A WordPress plugin that keeps your site lightweight by preventing the Freemius middleware from ever coming into play. Best when running Freemius' own "Freemius Fixer" plugin while this is enabled to purge existing Freemius data while this keeps it away. *NOTE:* This plugin manually specifies the plugins that use Freemius to then…
<?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 plugins that include it.
* @wordpress-muplugin
* Plugin Name: Freemius Killer
* Description: Keep your site lightweight by preventing the Freemius middleware from ever coming into play. Best when running Freemius' own "Freemius Fixer" plugin while this is enabled to purge existing Freemius data while this keeps it away. *NOTE:* This plugin manually specifies the plugins that use Freemius to then intercept them. As such, manual editing of this plugin is likely required. <a href="https://gist.github.com/KZeni/7afbd8b9a94c23aa0a9133d4ce767d0b" target="_blank">See Gist on GitHub for details &rarr;</a>
* Version: 1.0.1
* Author: KZeni + Austin Passy
* Author URI: https://gist.github.com/KZeni/7afbd8b9a94c23aa0a9133d4ce767d0b
* Plugin URI: https://gist.github.com/KZeni/7afbd8b9a94c23aa0a9133d4ce767d0b
* phpcs:disable
*/
if (!\is_blog_installed()) {
return;
}
// Create the Freemius Stub in case other plugins use their own global we need to override.
$freemius_stub = new class {
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 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;
@KZeni
Copy link
Author

KZeni commented May 18, 2024

Big thanks to @thefrosty for the initial set of code that I built this out from.

For those that want to keep this code lightweight & entirely customized/tailored for their specific site, I recommend starting with https://gist.github.com/thefrosty/d9bb001c05a407ba1aaa60c8b75aeb43 (of course referencing this if you have similar needs as what this is already accommodating.) This can be important when a plugin should be upgraded via Freemius & should be largely left as-is for that specific site whereas my Gist above might want to make that plugin Freemius-free.

For those who want to just install a plugin without touching any code, this is what I'd like to have this grow into. As of writing, it's just the Menu Image + Post Snippets + TablePress plugins, but (as the code above mentions in a few spots) I welcome any suggested revisions to be made here to add support for another plugin, improve reliability, etc.

If you have an update that adds support for a new plugin, avoids an error due to a plugin calling a function not yet accounted for, or anything like that... please simply comment your revision/edit here. I'll look to get any/all comments implemented to have this potentially grow into a one-click Freemius Killer that accounts for most/all plugins.

@KZeni
Copy link
Author

KZeni commented May 18, 2024

Of course, let me know if anyone finds it better to have this implemented as a full GitHub repository when it comes to suggesting edits/etc and I'll do that to replace this. I kinda just kept it as a Gist as a simple starting point.

@thefrosty
Copy link

Very nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment