The Plugin Generated X Characters of Unexpected Output During Activation (Wordpress)

The plugin generated X characters of unexpected output during activation (WordPress)

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.

The plugin generated xxx characters of unexpected output during activation

Remove space from start of tags. remove addHeaderCode(); from top and add this code add_action('wp_head', 'addHeaderCode'); to your file after addHeaderCode() function. its definitely resolve your problem.

The plugin generated 2651 characters of unexpected output during activation, why?

For this error

Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'activation' not found or invalid function name ..

You'll wan't to call the method of your object (class). To do that you can pass an array to the callback, the first element is the class name (in static calls) or an instance of the object, the second element is the method name such as:

class BOJ_Forum_Roles {

public function __construct() {
register_activation_hook( __FILE__, [$this,'activation'] );
register_deactivation_hook( __FILE__, [$this,'deactivation'] );
}

public function activation(){...}

public function deactivation(){...}
}

In core PHP call_user_func_array() is called like this

 call_user_func_array([$this,'activation'], $args);

http://php.net/manual/en/function.call-user-func-array.php

It's possible output from this error is giving you the original error you were seeing.

Static Calls

Just for completeness if you had

public static function activation(){...}

You would call it this way (static)

class BOJ_Forum_Roles {

public function __construct() {
register_activation_hook( __FILE__, [__CLASS__,'activation'] );
register_deactivation_hook( __FILE__, [__CLASS__,'deactivation'] );
}

public static function activation(){...}

public static function deactivation(){...}
}

Using the __CLASS__ constant is preferable to putting in the class name, in PHP5.5+ you can also do it this way self::class, although I believe the constant is a bit faster. I think the same holds true for static::class which would be late static binding. And of course you can always do this (in 5.5+) BOJ_Forum_Roles::class which in this example makes little sense, but it can be useful with namespaces.

UPDATE

showing...Notice: Only variables should be assigned by reference in

$role =& get_role('administrator');

Remove the Amp, as you are assigning the results of a function by reference. I am not certain, but if it's an object it's passed by reference anyway. It dosn't matter because you probably shouldn't be modifying it in your function and in fact this just caught my attention (in deactivation):

$role =& get_role('administrator');
...
foreach ($roles_to_delete as $role) {
...
}

You are re-assigning the $role variable in the loop. This may or may not cause issues (I can't tell for sure without testing it), but overwriting it is probably a simple over site on your part. It's generally bad practice to overwrite a variable this way (as the assignment of a loop) if it's been previously declared as often this would not be an intentional thing.

Cheers!

Error message - The plugin generated 1 characters of unexpected output during activation in wordpress

if you are using dreamweaver then there is a option "Apply source formatting" under control menu, try that and it will remove unwanted whitespaces.

and also make sure there are no any extra whitespaces or line breaks after the ?>(php closing tag at the end of your page..)



Related Topics



Leave a reply



Submit