The plugin generated X characters of unexpected output during activation (WordPress)
2 probably reasons:
1) You are doing an output (like echo
or etc) in wrong place.
- Do you want to output a message in
admin
dashboard? - useadmin_notices
hook and output there... Do you want to output a message in front-end? - find appropriate places with hooks (like
the_content
orwp_footer
or whatever).Don't output anything either in
register_activation_hook
or outside of WordPress standard hooks, no-one should do that.**
2) if you aren't doing any output intentionally, then maybe some php
error happens? If so, put this code temporarily in functions.php
and then activate the plugin - you will see the error.
define('temp_file', ABSPATH.'/_temp_out.txt' );
add_action("activated_plugin", "activation_handler1");
function activation_handler1(){
$cont = ob_get_contents();
if(!empty($cont)) file_put_contents(temp_file, $cont );
}
add_action( "pre_current_active_plugins", "pre_output1" );
function pre_output1($action){
if(is_admin() && file_exists(temp_file))
{
$cont= file_get_contents(temp_file);
if(!empty($cont))
{
echo '<div class="error"> Error Message:' . $cont . '</div>';
@unlink(temp_file);
}
}
}
Had the same error, but only with 6 characters ) so... in my case I had empty lines after PHP closing tag ?> - that will cause this error too.
I think there may be two issues here that are causing the problem. First is that I don't think wordpress expects any output when the plugin activation hook is called so it may be complaining about that. Second is that plugin activation hooks are called fairly early in the wordpress program flow, so, it's probably being called before headers are sent. If ANY output is generated before calling header()
then PHP usually complains.
Usually the plugin activation routine is reserved for basic setup of the plugin, calls to things like set_option()
and the like.