Skip to content

Instantly share code, notes, and snippets.

@thefrosty
Created January 12, 2024 17:39
Show Gist options
  • Save thefrosty/d9bb001c05a407ba1aaa60c8b75aeb43 to your computer and use it in GitHub Desktop.
Save thefrosty/d9bb001c05a407ba1aaa60c8b75aeb43 to your computer and use it in GitHub Desktop.
Create an override function, as to bypass Freemius in some less than smart plugins.
<?php
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.0.0
* Author: Austin Passy
* 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.
$freemius_stub = new class {
public function add_action($tag, $function_to_add, $priority = 10, $accepted_args = 1)
{
return;
}
};
/**
* 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;
@KZeni
Copy link

KZeni commented May 17, 2024

Just giving a mention that I came across this Gist via https://austin.passy.co/2024/disable-freemius-in-wordpress-plugins/ (for those that might want more details on this.) Looks to be very helpful and it's nice to see only a few months old for it to still apply to the current Freemius setup.

@KZeni
Copy link

KZeni commented May 17, 2024

Okay, I went and fleshed this out to also account for the TablePress & Post Snippets plugins while then avoiding a few errors that came up with how they each then tried to call functions from their main Freemius class which this didn't yet account for (a good number more than just add_action, as it turns out.)

Considering this Gist serves as a nice reference / starting point for those who want to go fully self-implemented & self-managed, I went ahead and created a fork of this at https://gist.github.com/KZeni/7afbd8b9a94c23aa0a9133d4ce767d0b where I fleshed it out quite a bit. I also then made it clear that I welcome any/all revisions for anyone who wants to add another plugin to be accommodated with the latest plugin code by default (to potentially even grow into a plugin that auto-updates to streamline & allow that support to keep growing over time.)

That way, this can stay lightweight while my fork (https://gist.github.com/KZeni/7afbd8b9a94c23aa0a9133d4ce767d0b) keeps growing to help those who just want to download & install a plugin without needing to touch any code.

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