-
-
Save yward/ed454befdfad0070f75bad0bc630d686 to your computer and use it in GitHub Desktop.
Create an override function, as to bypass Freemius in some less than smart plugins.
This file contains hidden or 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 | |
declare(strict_types=1); | |
/** | |
* Create an override function, as to bypass Freemius in stupid plugins. | |
* @wordpress-muplugin | |
* Plugin Name: Freemius Stub | |
* Description: Global override for Freemius' "loader". | |
* Version: 1.1.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. | |
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 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; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment