random code at the end of file after plugin upload

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