I’m getting this message each time I activate my plugin:
The plugin generated 80 characters of unexpected output during activation. If you notice âheaders already sentâ messages, problems with syndication feeds or other issues, try deactivating or removing this plugin.
The only way I can suppress the message is to wrap my activation function code in a conditional (**see below).
How should I rewrite this to prevent the alert?
function myPlugin($post)
{
echo "Whatever is here throws an unexpected output alert when the plugin isa activated";
//I can place code here without issue, but anything that is output via echo throws the alert.
}
register_activation_hook(__FILE__, 'myPlugin');
Wrapping the function code in the conditional suppresses the alerts:
function myPlugin($post)
{
global $pagenow;
if ( is_admin() && $pagenow !== 'plugins.php' ) {
echo "No more alerts when its wrapped this way";
}
}
?>
When you get this kind of message is usually means your plugin had a syntax error and was generating that kind of error messages because of how the loading on activation is handled, i.e. HTTP headers are sent after the error message is display. Your plugin’s error message is loaded in an
<iframe>
; have you done a “View Source” on the<iframe>
to see if there’s an obvious error message?Also, you should consider getting an HTTP debugger which can help with this kind of things:
Windows has the excellent and free Fiddler.
For Mac OS X there’s HTTPScoop (not great, but inexpensive at US$15.)
There’s also Charles for Windows/Mac/Linux (US$50 – I may break down and buy it one day. Wish I could get Fiddler on Mac, but since Fiddler comes from Microsoft I don’t hold my breath.)
UPDATE
Based on the comments below, here’s a screen of me using “Inspect Element” in Safari (but you can do the same with Chrome and FireFox, or similar with IE and the Web Developer Toolbar):
(source: mikeschinkel.com)
You can grab that
<iframe>
d URL and load it directly in your browser to make the process of debugging easier. Something in your plugin is sending qheader()
after an error message is thrown, that’s what that error message means.(source: mikeschinkel.com)
BTW, I just added a stray character and hence syntax error in my plugin to get it to throw an error which is why you see the error as you do.
USE DEBUG:
(creates log file error_activation.txt in your plugin folder)
Sry, for the late answer, but I just stumbled upon and the answer is really simple:
Never echo anything inside functions that are used on de-/activation/uninstall hooks. This will always result in the above mentioned error message.
I was having the same issue, i tried to remove the code and did everything but still the same problem
the real solution for me was the following.
my plugin file ended at line 69 and there were 7 more spaced after the last php code so in the editor the file was up to 66, my error was “The plugin generated 7 characters of unexpected….” when i removed extra lines up to 69 the was error gone,
I’ve just been exploring this problem and what I’ve found is that the problem can be caused by errors in the php (like calling a deprecated function) which WordPress suprresses, FTP garbling or by having code outside of the ‘php’ tags.
I don’t think that Mike is correct above. The unexpected output issue is handled differently than a fatal error, firstly, wordpress suppresses the issue, it gives the ‘unexpected output’ message and more importantly it does actually activate the plugin and redirects back to the plugin page whereas with an error it just dies. I don’t think that there will be anything useful in the frame and I don’t think that the headers will let you the output that wordpress didn’t expect which is what will provide the clues for solving the underlying issue.
There are a number of solutions to getting at the unexpected output text which require either hacking the plugins.php file or setting an event handler for the ‘activate_plugin’ action.
FWIW, you can find my solutions mirror here (work in progress!) with some links to other people’s solutions from which I borrowed shamelessly!
I had this problem too. It occured thad the plugin php file had bad encoding. I simply copied whole content to a new notepad file and saved it with ansi encoding. Error message dissapeard. Of ccourse now there are language issues but it’s some other case. Regards