PHP Fatal error when using plugin_basename

I’ve encountered this issue a few times before. It’s a simple matter of adding this to the top of your plugin beneath the comments block. It appears that the way plugin_basename returns the value doesn’t play nicely with much else.

$basename = plugin_basename(__FILE__);

Then replace this line:

define( 'SEND_INVITATION_PLUGIN_BASENAME', plugin_basename(__FILE__) );

With this instead:

define( 'SEND_INVITATION_PLUGIN_BASENAME', $basename );

Updated based on feedback.

So it appears you’re not getting accessing to the function plugin_basename, for the sake of a temporary workaround in your plugin add this function.

function the_plugin_basename($file) {
    $file = str_replace('\\',"https://wordpress.stackexchange.com/",$file); // sanitize for Win32 installs
    $file = preg_replace('|/+|',"https://wordpress.stackexchange.com/", $file); // remove any duplicate slash
    $plugin_dir = str_replace('\\',"https://wordpress.stackexchange.com/",WP_PLUGIN_DIR); // sanitize for Win32 installs
    $plugin_dir = preg_replace('|/+|',"https://wordpress.stackexchange.com/", $plugin_dir); // remove any duplicate slash
    $mu_plugin_dir = str_replace('\\',"https://wordpress.stackexchange.com/",WPMU_PLUGIN_DIR); // sanitize for Win32 installs
    $mu_plugin_dir = preg_replace('|/+|',"https://wordpress.stackexchange.com/", $mu_plugin_dir); // remove any duplicate slash
    $file = preg_replace('#^' . preg_quote($plugin_dir, '#') . "https://wordpress.stackexchange.com/"^' . preg_quote($mu_plugin_dir, '#') . '/#','',$file); // get relative path from plugins dir
    $file = trim($file, "https://wordpress.stackexchange.com/");
    return $file;
}

Then in your plugin change any references to the function plugin_basename(), to the_plugin_basename() instead. This will get us past the error of not being able to call that function and with a little luck, we might see another error telling us what is going on.