mailgun / wordpress-plugin

Mailgun's Wordpress Plugin
GNU General Public License v2.0
48 stars 53 forks source link

Fatal error on lists page when another plugin redeclares wp_mail() #164

Closed n-dawson closed 1 year ago

n-dawson commented 1 year ago

When you activate the Mailgun plugin alongside any other plugin which attempts to override wp_mail(), there's a fatal error on the Settings -> Mailgun Lists page:

_Fatal error: Uncaught Error: Call to undefined function mg_api_getregion() in /Users/nathan/Local Sites/mailgun/app/public/wp-content/plugins/mailgun/mailgun.php:221

The line in question is part of the api_call() method.

mg_api_get_region() is declared within mg-filter.php but it's possible to end up in a situation where that file is never loaded.

From the main plugin file, starting on line 83:

if ($this->get_option('useAPI') || (defined('MAILGUN_USEAPI') && MAILGUN_USEAPI)) {
    if (!function_exists('wp_mail')) {
        if (!include __DIR__ . '/includes/wp-mail-api.php') {
            $this->deactivate_and_die(__DIR__ . '/includes/wp-mail-api.php');
        }
    }
} else {

If wp_mail() is declared elsewhere, wp-mail-api.php and in turn mg-filter.php aren't included.

This means the plugin is able to operate in a half loaded state where it's relying on functions that aren't available.

Steps to reproduce:

  1. Setup a blank WordPress install
  2. Install and activate the Mailgun plugin
  3. Install and activate a barebones plugin which redeclares wp_mail(). I've included code below. Note that order is important. The plugin has to load BEFORE Mailgun and since they're loaded alphabetically by file/folder name, use something like abc.php

Barebones plugin code:

<?php
/**
 * Plugin Name: WP Mail Test
 * Version: 1.0.0
 */

if (!function_exists('wp_mail')) {
    function wp_mail() {
        return false;
    }
}
oleksandr-mykhailenko commented 1 year ago

Hello @n-dawson Thanks for you reporting. We will fix this soon

oleksandr-mykhailenko commented 1 year ago

Hello @n-dawson New version was released and bug was fixed

midweste commented 7 months ago

I'm still getting this error on the lists page. Version 1.9.9

Fatal error: Uncaught Error: Call to undefined function mg_api_get_region() in /app/web/wp-content/plugins/mailgun/mailgun.php:222
Stack trace:
#0 /app/web/wp-content/plugins/mailgun/mailgun.php(286): Mailgun->api_call('lists', Array, 'GET')
#1 /app/web/wp-content/plugins/mailgun/includes/lists-page.php(38): Mailgun->get_lists()
#2 /app/web/wp-content/plugins/mailgun/includes/admin.php(234): include('/app/web/wp-con...')
#3 /app/web/wp-includes/class-wp-hook.php(324): MailgunAdmin->lists_page('')
#4 /app/web/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters('', Array)
#5 /app/web/wp-includes/plugin.php(517): WP_Hook->do_action(Array)
#6 /app/web/wp-admin/admin.php(259): do_action('admin_page_mail...')
#7 {main}
  thrown in /app/web/wp-content/plugins/mailgun/mailgun.php on line 222