title: Ajax broken by Wordpress warnings: solve trough ob_start()?
body: <p>I am writing a plugin for <code>WordPress</code>. My goal is make it work for everyone. Some pages use <code>ajax</code> responses. Some users have activated the WP_DEBUG constant that shows errors and warnings from themes and other plugins. </p>
  
  <p>This breaks my Ajax PHPs because I include the <code>Wordpress</code> Core, and then WP can show warnings in some blogs!</p>
  
  <p>The old way I solved this, is:</p>
  
  <pre><code>&lt;?php
  ob_start();
  //The wordpress core require
  ob_end_clean();
  
  //Now the ajax response:
  echo '0';
  ?&gt;
  </code></pre>
  
  <p>However, one user reported a very strange bug: the <code>ajax</code> page never response, only works in Opera, and Google Chrome says: Error 330 (net::ERR_CONTENT_DECODING_FAILED):</p>
  
  <p>Digging in the user web-server, I found that WP configuration, or a plugin or elsewere uses the ob_start("ob gzhandler"). </p>
  
  <p>The ob_get_status(true) shows in my working webserver:</p>
  
  <pre><code>Array
  (
      [0] =&gt; Array
          (
              [chunk_size] =&gt; 4096
              [type] =&gt; 1
              [status] =&gt; 0
              [name] =&gt; default output handler
              [del] =&gt; 1
          )
  
      [1] =&gt; Array
          (
              [chunk_size] =&gt; 0
              [size] =&gt; 40960
              [block_size] =&gt; 10240
              [type] =&gt; 1
              [status] =&gt; 0
              [name] =&gt; default output handler
              [del] =&gt; 1
          )
  
  )
  </code></pre>
  
  <p>And in the buggy web-server:</p>
  
  <pre><code>Array
  (
      [0] =&gt; Array
          (
              [chunk_size] =&gt; 4096
              [type] =&gt; 1
              [status] =&gt; 0
              [name] =&gt; default output handler
              [del] =&gt; 1
          )
  
      [1] =&gt; Array
          (
              [chunk_size] =&gt; 0
              [size] =&gt; 40960
              [block_size] =&gt; 10240
              [type] =&gt; 1
              [status] =&gt; 0
              [name] =&gt; default output handler
              [del] =&gt; 1
          )
  
      [2] =&gt; Array
          (
              [chunk_size] =&gt; 0
              [size] =&gt; 40960
              [block_size] =&gt; 10240
              [type] =&gt; 1
              [status] =&gt; 0
              [name] =&gt; ob_gzhandler
              [del] =&gt; 1
          )
  
  )
  </code></pre>
  
  <p>The sequence in my user web-server is:</p>
  
  <ul>
  <li>My code calls ob_start()</li>
  <li>Include WP core, WP initializes all and call ob_start("ob gzhandler")</li>
  <li>When my code call ob_end_clean() it fails.</li>
  </ul>
  
  <p>I need a safe way to hide the WP warnings, but I can't break GZIP enabled configurations ( some plugin I suspect). If is not possible I prefer leave breaking ajax in warning systems and forget the buffer method.</p>
  
  <p>I think a clean way may be:</p>
  
  <pre><code>$buffers = count(ob_get_status(true));
  ob_start();
  //The wordpress core require
  if (count(ob_get_status(true)) == $buffers + 1) {
  ob_end_clean();
  } else {
  ob_flush();
  }
  //Now the ajax response:
  echo '0';
  </code></pre>
  
  <p>But I'm afraid some of the infinite combinations through PHP versions and configs, WP versions, plugins and configurations breaks somebody. What do you think is a good way to solve this problem?</p>