I uploaded to a WordPress site (3.3.1) a plugin that works perfectly in my other sites (3.3.1 and 3.4), but when try to activate it I get Fatal Error. When I go to check the plugin's main file content to do some changes and identify the error I detect that at the end of my code appears some random code from my file repeated.

If I edit it and save again another random code is placed at the end of the file again.

Any suggestion will be appreciated, even if are suggestions to do more research about it. I really don't know what to check for this issue.

Edition to add information requested:

I test deactivating all the plugins and with Twenty Eleven theme and I obtain the same behaviour

Example of the random code added

Plugin Name: My plugin
Description: desc
Version: 1.0

 * Version of WordPress
 * @global  string  $wp_version
global $wp_version;

$exit_msg = __('This plugin require WordPress 3.1 or newer','seo-pressor').'. <a href="http://codex.wordpress.org/Upgrading_WordPress">'.__('Please update','seo-pressor').'</a>';
if (version_compare($wp_version, "3.1", "<")) { 

// Avoid name collisions.
if (!class_exists('WPPostsRateKeys')) {
    class WPPostsRateKeys
(... long piece of code ...)

// create new instance of the class
$WPPostsRateKeys = new WPPostsRateKeys();
if (isset($WPPostsRateKeys)) {
    // register the activation function by passing the reference to our instance
    register_activation_hook(__FILE__, array(&$WPPostsRateKeys, 'install'));
    register_deactivation_hook(__FILE__, array(&$WPPostsRateKeys, 'uninstall'));

As you can see at the end was added the "][" that make my code fail.

Another information: when I open my text file using WordPress edit plugin file feature I see the random code at the end that will make my code file, but if I open the same file with the cPanel file manager this utility ask me for the encoding first (assign the file UTF-8) and opens it without any extra code added at the end. Anyway the activation of the plugin continue failing in WordPress due to this extra code.

I already save my files as FTP-8 without BOM and follow all the suggestions from http://www.toddlahman.com/the-plugin-generated-x-characters-of-unexpected-output-during-activation and doesn't works.

When in the WordPress editor I open the file the random text appears but when I open the same file using my FTP client the random text doesn't appears.

How do I need to code or save my PHP file so it works correctly?

Thanks in advanced Leticia

  • Try disabling all other plugins and switch to Twenty Ten/Eleven. See if the problem persists and update question accordingly.
    – mrwweb
    Commented Jul 24, 2012 at 20:49
  • Possibly a UTF vs ASCII issue? Check to see that the file generating the code is saved as UTF-8. Commented Jul 24, 2012 at 20:49
  • 1
    In that case could you post a sample of the random code? That would help narrow down the cause. Commented Jul 24, 2012 at 21:10
  • 1
    Are you sure about (3.3.1 : doesn't works) & (3.3.1 and 3.4 : works)? . . . If the plugin works in other WordPress installations, wouldn't the problem be with WP instead of the plugin?
    – brasofilo
    Commented Jul 29, 2012 at 16:21
  • 1
    As I said: Save the file with Notepad++ (UTF-8 without BOM). Then upload it via FTP only. Then activate. If this doesn't work, go back, delete the parts (with Notepad++ again) that are not in the code you showed above ↑ and upload it again via FTP. Btw: This is highly off topic and should be closed.
    – kaiser
    Commented Jul 29, 2012 at 17:22

3 Answers 3


Check if you have a class or function with many echo's, that are called on the functions register_activation_hook or register_deactivation_hook. Also - this functions must use static functions.

Also, is it possible that you have a var_dump() inside your source?

It is important that you not have an output (like echo or var_dump) on activation or deactivation of the plugin. This not a part of the activation process. WP checks this and gives this warning for plugins that generate many strings on the include. Check that your output only works on the right hooks for output, not for activation and so on.

Also, include plugins using the hook plugins_loaded (or init as an alternative) not via new, it's not the same point on stack trace of WordPress. Like the following example:

class WPPostsRateKeys {

    static private $classobj;

     * Handler for the action 'init'. Instantiates this class.
     * @since   2.0.0
     * @access  public
     * @return  $classobj
    public function get_object() {

        if ( NULL === self :: $classobj ) {
            self :: $classobj = new self;

        return self :: $classobj;

    public function __construct() {



if ( function_exists( 'add_action' ) && class_exists( 'WPPostsRateKeys' ) ) {
    add_action( 'plugins_loaded', array( 'WPPostsRateKeys', 'get_object' ) );

Also possible, but in other answers and the link from question.

  • a whitespace before the start tag of php <?php
  • Leave the closed php tag at the end of file ?>
  • The file must encoded as Unicode-file, like UTF-8
  • thank, now the plugin is activated but seems like an error occurs because I get a blank page for any WordPress page after I activate the plugin with the changes you suggest that I haven't before: - leave the closed php tag on the end of file ?>, - use the plugins_loaded to activate the plugin
    – leticia
    Commented Jul 31, 2012 at 15:06
  • Maybe you copy the plugin on a gist or check in in an open repo to test it?
    – bueltge
    Commented Jul 31, 2012 at 17:22
  • I will do some more tests, if fails I will do, thanks.
    – leticia
    Commented Aug 2, 2012 at 21:48
  • OK. I have write a little bid more in my answer, please read them and check your sourece for this hints.
    – bueltge
    Commented Aug 3, 2012 at 8:06

looks like a UTF-8 vs ASCII issue, try resaving the file as UTF-8 and uploading via FTP.

  • The file is already as UTF-8 and uploaded via FTP. I try resaving it, besides as a UTF-8 without BOM and I get the same problem. thanks
    – leticia
    Commented Jul 29, 2012 at 21:06

Try upload it with FileZilla option Force UTF-8. Beside you can try with "mc" ftp client if you are on Linux.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.