Plugin Conflict Resolution: iPassion-Tell-a-Friend vs All-in-one-SEO

Sometimes plugins don’t get on with each other. If you try running the iPassion-Tell-a-Friend plugin alongside All-in-one-SEO Pack, then you may run into problems. I was recently asked to get these two plugins playing together nicely by a client who was getting a “Headers Already Sent” error message whenever data was submitted through the Tell-a-Friend form.

The problem is that the Tell-a-Friend plugin redirects users to a success page using header("Location: $successPage");. This instruction needs to be sent to the browser before any other code, but by the time Tell-a-Friend sent its redirect instruction All-in-one-SEO Pack had already output some meta tags, hence the error.

Getting Tell-a-Friend to go first, redirecting the user to the success page before All-in-one-SEO does its thing, fixed the conflict.

Both plugins hook into WordPress’s wp_head action using the add_action function. Out of the box, Tell-a-Friend hooks in like this: add_action ('wp_head', 'addTellaFriendSender');

This line of code tells WordPress that when it gets to the wp_head hook, it should call the addTellaFriendSender() function, which is the function that does most of the Tell-a-Friend plugin’s work.

Changing this line to the following resolved the clash between Tell-a-Friend and All-in-one-SEO: add_action ('wp_head', 'addTellaFriendSender', '1');

Every function that’s hooked into wp_head (or any other hook) has a priority between 1 and 15 (the lower the number, the higher the priority). The add_action function’s third parameter, $priority, sets this priority. The parameter is optional, and defaults to 10, so the out of the box add_action call hooks addTellaFriendSender into wp_head with a priority of 10, which is the same as All-in-one-SEO Pack’s priority.

The modified add_action call hooks addTellaFriendSender into wp_head with a priority of 1, moving it to the front of the queue and making sure that its redirection instruction comes before anything else that might cause a conflict.

3 Responses to “Plugin Conflict Resolution: iPassion-Tell-a-Friend vs All-in-one-SEO”

  1. Adam Says:

    If addTellaFriendSender() is the function with the header("Location: $successPage"); code in it, it should probably be hooked much earlier than at wp_head to avoid conflict with any other plugin that may output HTML there. It should probably hook in at init which is when WordPress has been bootstrapped but before any headers have been sent. Just my 2 cents. Thanks.

  2. Tim Holt Says:

    You’re probably right, which is a shame because as the article stands it’s a good introduction to the $priority parameter, but if we use add_action ('init', 'addTellaFriendSender'); instead then it isn’t.

  3. Tim Holt Says:

    Update: New versions of the plugin incorporate the fix suggested here, so in future this problem shouldn’t arise unless your plugin is out of date.

Leave a Reply

You must be logged in to post a comment.