Hi authors!
I’m a plugin developer and I want to share and discuss something that I frequently have to deal with when providing support to my customers about my plugins.
I’m not a native English speaker so the tone of this post may be misinterpreted, forgive me in advance for that.
The context
A generic customer reaches me reporting a fatal error when trying to activate my plugin. The error is:
Fatal error: Cannot redeclare tgmpa() (previously declared in /wp-content/plugins/my-plugin/libs/tgm/class-tgm-plugin-activation.php:2126) in /wp-content/themes/example-theme/inc/tgm-plugin-activation/class-tgm-plugin-activation.php on line 2126
So the TGMPA class bundled with the theme is redeclaring the tgmpa function although already declared by the one bundled with the plugin. As all we already know, recent versions of TGMPA library should take care already of that with conditional blocks, so the first thing I check is that the theme is up to date. Unfortunately, the theme is up to date as well as the TGMPA library. So what?
The issue
Theme’s developers often customize the TGMPA class to play well with their themes. While inspecting the customized class I often come across what looks like a search-and-replace typo:
if ( ! function_exists( 'whatever-theme-slug' ) ) {
function tgmpa( $plugins, $config = array() ) {
This always-true conditional is silent most of the time, hence hard to spot when testing the theme, yet trivially destined to generate a fatal error when an active plugin includes TGMPA.
For the sake of completeness, here is the correct vanilla one:
if ( ! function_exists( 'tgmpa' ) ) {
function tgmpa( $plugins, $config = array() ) {
The outcomes (fatal error apart)
I need then to explain to that customer that theme contains that little typo which I can fix by myself, but at every theme update they will face the issue again. So I invite the customer to report the issue to the theme developers etc.
Some theme’s developers immediately react and fix the glitch, while others are less prone to intervene. Once I was even told that it was my fault to provide the TGMPA class because it’s made for themes only, which is clearly a nonsense.
Long story short, I can’t run checks for TGMPA presence right before including the class in my plugins, as they are loaded before the theme (if you know a way, please let me know!) so I beg you to have a look at your TGMPA implementation being typo-free, because this has quite an impact on compatibility.
Sincerely,
VonStroheim