0

I am coding a plugin for WordPress. When I’m using the function register_activation_hook, I get the following error:

The plugin generated 28 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.

Relevant code:

register_activation_hook(__FILE__, function(){
echo "<script>alert('ok')</script>";
});
JoshDM
  • 4,939
  • 7
  • 43
  • 72
Walid Naceri
  • 160
  • 5
  • Your activation hook is outputting a – andrewsi Jul 09 '13 at 14:02

1 Answers1

0

Wordpress is probably being called before headers are sent. If any output is generated before issuing header(), then PHP/Wordpress usually complains.

Try this instead:

function my_activation_func() {    
    echo "<script>alert('ok')</script>";
}

register_activation_hook( __FILE__, 'my_activation_func' );

Read the documentation here.