
While developing a new WordPress plugin I ran into a common problem when the plugin was activated. The following message popped up:
The plugin generated 1616 characters of unexpected output during activation. If you notice “headers already sent” messages, problems with syndication feeds or other issues, try deactivating or removing this plugin.
The most common causes are:
1. A white space before or after the PHP opening or closing tags
2. A file encoded in UTF-8
3. Another issue when something is called at the wrong time, or a call that cannot be resolved without intervention
4. Using the WordPress add_option function. Switching to update_option instead can resolve the problem.
The first is the most common mistake for new programmers. Once the space is removed before or after the PHP opening and closing tags try deactivating and reactivating the plugin to see if the message is gone.
The second stumped me. I use several local development servers including Uniform Server, WAMP Server, and XAMPP. The files were encoded in UTF-8, the universal language encoding that is the standard, but the server threw errors. I finally converted the files to ANSI encoding, and the problem was fixed. Some web hosts also run software that generate this error, so it is best to encode the plugin in ANSI to avoid unexpected problems.
If the first two causes have been eliminated, and the problem persists then this issue needs to be tracked down and eliminated, otherwise it might cause problems. To save the error message to debug the problem the following code snippets can help:
function tl_save_error() { update_option( 'plugin_error', ob_get_contents() ); } add_action( 'activated_plugin', 'tl_save_error' ); |
Then to display the error message:
echo get_option( 'plugin_error' ); |
Or you could do the following:
file_put_contents( 'C:\errors' , ob_get_contents() ); // or any suspected variable |
If you have another method to save and display these error messages share them.
My case was number 2, I had the file with UTF-8 coding, I changed it and it worked. Thanks!
Sir thanks for your plugin its a really great plugin ,i have updated your plugin spam free wordpress ,but its asking for update again and again what to do?
http://www.danihowto.com
and
http://www.myblogtricks.com
This a W3 Total Cache problem. Clear your database cache, and it should resolve the issue. If not, clear all caches. (12:45 pm on August 12, 2012)
Hello, thanks for your tips. I have the same issue. When I try to save my files in ANSI and select US-ASCII since I haven’t the ANSI option. I’m using Zend Studio. This is the same? since doesn’t solve the problem but I’m almost sure this is the issue in that hosting because the plugin is working perfectly in others servers.