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.
October 28th, 2008 at 9:59 pm
If
addTellaFriendSender()is the function with theheader("Location: $successPage");code in it, it should probably be hooked much earlier than atwp_headto avoid conflict with any other plugin that may output HTML there. It should probably hook in atinitwhich is when WordPress has been bootstrapped but before any headers have been sent. Just my 2 cents. Thanks.October 31st, 2008 at 9:19 am
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.November 19th, 2008 at 10:19 am
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.