The plugin generated 80 characters of unexpected output!

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";
        }
}
 ?>

6 Answers
6

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):

Screenshot of Element Inspector on Safari with the WordPress plugin error IFRAME
(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 q header() after an error message is thrown, that’s what that error message means.

Loading WordPress Plugin Activation URL directly from the browser
(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.

Leave a Comment