How to handle “The plugin generated x characters of unexpected output” errors in WordPress

Some errors are hard to trace, especially when no line of error or function/variable is

If you ever ecounter “The plugin generated x characters of unexpected output” in your WordPress plugin development, a simple solution is to include the following line in your function/method:

file_put_contents(__DIR__ . '/activation_log.txt', ob_get_contents());

This will write any output to a file in the current directory where the file containing the function/method resides.

Advertisements