• When I activate your plugin I am getting the following error notice from wpMandrill:

    Mandrill: wp_mail has been declared by another process or plugin, so you won't be able to use Mandrill until the problem is solved.

    I don’t readily see where you are declaring wp_mail but I need wpMandrill to work and I would love to use this plugin also. Could you please take a look at it and let me know where you are declaring the wp_mail function?

    Thanks in advance!

    https://www.ads-software.com/plugins/back-end-instructions/

Viewing 9 replies - 1 through 9 (of 9 total)
  • Thread Starter Ken Lewis

    (@trinity13)

    I found the issue.

    instructions.php
    
    57  /**
    58   * I know.  I'm sorry.
    59   */
    60
    61  if( !function_exists('wp_set_current_user')	) {
    62    require(ABSPATH . WPINC . '/pluggable.php');
    63  }

    This causes wp_mail (and a lot of other functions) to be declared before it should.

    Since I don’t know why you did this, I don’t know how to fix it. I’d be happy to try to help you fix it if you can let explain why you need that code there.

    Plugin Author Doodlebee

    (@doodlebee)

    It’s there because the plugin needs access to the current logged-in user level. The order WordPress loads things means that the plugin gets loaded *before* the user level is checked. That line of code is to force the user level to be checked before the plugin loads. The reason is because the plugin relies on knowing what the user level is for the end user – logged in or not. That’ how a lot of the functionality is displayed properly (i.e. not displaying the back-end link to anyone but admins, knowing which user level to show instructions to, etc.) it’s a fairly common issue, actually, but one I haven’t yet found a workaround for.

    In any case, it doesn’t make sense that wp_mail would stop working because of this call. I know I have it running on several sites, and it doesn’t affect wp_mail at all. since wpMandrill is a mail plugin, I’m wondering if the issue lies with that plugin (plugin conflict?) I’ve never used it, so I don’t know. I’d have to look at the code for that plugin.

    EDIT: according to the plugin description: “It replaces the wp_mail function included with WordPress.” So that’s probably why you’re getting an error – it’s not checking to see if mail is actually loaded before it attempts to do whatever it does. I can’t really do anything for that – the plugin author should have it in the code to check and see if wp_mail is loaded and running before it assumes it’s not. (that’s why I have an”if” statement before calling pluggable.php – if it’s loaded, don’t load it again) There are a LOT of plugins that use the pluggable include to access user information – this is a pretty common solution to the problem. I would LOVE to find an alternative solution to obtaining that information though, because not everyone checks to see if stuff is loaded before they start doing stuff to it, and it’s kind of a common issue with plugin conflicts.

    Has a fix for this been figured out? I’d like to add your plugin to a client’s site, but since I’m already using wpMandrill, I’m getting the same error.

    Plugin Author Doodlebee

    (@doodlebee)

    There’s nothing I can do to fix this. My plugin *requires* pluggable.php to be called in to function. I have it surrounded by an “if” statement, to ensure it doesn’t conflict with other plugins – i.e. if it’s already called, don’t call it.

    wpMandrill appears to be a premium plugin, so I can’t test my plugin with it, unless I buy it first. My *guess* would be that wpMandrill is also calling in pluggable.php – but their code doesn’t have an “if” statement wrapped around it – so it’s still trying to call it in even though it’s already been called. (but without access to the plugin files, I can’t verify that information)

    Plugins are called in alphabetical order. “b” comes before “w”, so mine is getting called first. Again, I’ve wrapped an “if” statement around my call to pluggable.php, so any plugin that was called before mine won’t have a conflict. but I can’t force the order of plugin load to change (nor would I want to) to make this go away. I can’t do anything about the plugins that are loaded after mine. if someone else needs pluggable.php to be loaded, and doesn’t check to see if it’s loaded yet, there’s really nothing I can do.

    If it’s a serious issue, I would recommend contacting the plugin author for wpMandrill. I’ve already done everything I can with my plugin to ensure it doesn’t conflict with other plugins – but if other plugin authors don’t put those checks in, I can’t do anything about that.

    And yes, I’m still searching for an alternative to calling in pluggable.php, but I have yet to find one.

    Plugin Author Doodlebee

    (@doodlebee)

    I did see that wpMandrill is now free. (when I checked before, it was not, or perhaps I was looking at the wrong plugin, I don’t know, but the one I saw before was premium only) I’ve just downloaded and checked it.

    wpMandrill rewrites the wp_mail() function. it doesn’t appear to check and see if it’s loaded first. (it kinda does – but if it is loaded, then it just spits out an error message and stops.) pulling in pluggable.php does load the wp_mail(0 function – but wpMandrill’s intent is to rewrite that function, and set it before the WP default function is written. So calling the pluggable file prevents it from doing this. The plugin could easily avoid this conflict (there are actually several out there that conflict with wpMandrill because of this) by either using rename_function(), or override_function(), but I guess he chose not to do that.

    In any case, I did find a possible solution that is working locally. Another plugin was having the same issue (calls in pluggable.php, and getting the same error in wpMandrill), and someone came along and popped in a solution that they used for one of their own, since the wpMandrill plugin author doesn’t seem to have a fix for his code.

    So try this, in instructions.php, change:

    /**
     * I know.  I'm sorry.
    */
    
    if( !function_exists('wp_set_current_user')	) {
      require(ABSPATH . WPINC . '/pluggable.php');
     }

    to this:

    /**
     * Call in my plugin with plugins_loaded instead of directly
     */
    function bei_call_pluggable() {
        if( !function_exists('wp_set_current_user')	) {
          require(ABSPATH . WPINC . '/pluggable.php');
        }
    }
    add_action('plugins_loaded', 'bei_call_pluggable');

    That’s working for me, locally.

    I’m currently working on this plugin to make some improvements, but they aren’t complete yet. I’ll be sure to put this in the next release (if you can verify that this works) so making the change won’t be affected on the next update.

    Sorry – where is this instructions.php file found?

    Is this something I can add to my child theme so this isn’t overridden on next WP/plugin update?

    Thanks!

    Plugin Author Doodlebee

    (@doodlebee)

    It’s a plugin. it’s the main file for the plugin. My plugin has absolutely nothing whatsoever to do with themes.

    Looks like it worked. Thanks!

    Plugin Author Doodlebee

    (@doodlebee)

    Excellent! Thank you for letting me know. I’ll be sure to have that in the next release.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Conflict with wpMandrill’ is closed to new replies.