Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a plugin that detects the useragent of a request made during the init hook and if it matches my desired value, I set a flag so that my own xml content is sent during the found_posts filter instead of the html that the theme sends.

the problem is that on a few rare sites, the theme is sending some of it's content before my plugin can send it's own which causes the the external site that is calling to have an xml error because there is non xml code before the bit my plugin sends.

I've tried installing the theme to my local server but the problem doesn't happen there, everything is ticketyboo! so I can only imagine that it is something to do with the server that the site is hosted on. It only seems to happen when someone has set their theme to use a custom homepage.

What could be causing this?

I can show what happens if I use the useragent switcher plugin for firefox and set it to use a new useragent of "Commentluv" and visit http://willtaft.com which shows the xml error . viewing the source of the page shows that my plugin didn't send it's content until most of the theme content had already been output

if I view http://willtaft.com/blog/ using the firefox set to send the 'Commentluv' useragent then everything is working as it should and I can see the xml my plugin sends.

This is driving me crazy! I can't replicate the problem on any of my sites, it only happens on a very few sites and then, only with sites using a custom home page.

I've even tried using an output buffer at the init stage if it detects that the Commentluv useragent is requesting the page and clearing it before my plugin sends the xml but even that wont work on the problem sites.

I'd love to hear any suggestions

share|improve this question
    
Any progress? Was my answer useful? Is there something missing? –  toscho Oct 6 '12 at 22:27
add comment

1 Answer

Hook into 'plugins_loaded', that should be early enough. Theme output cannot be sent at this stage, so you should be safe – if you really just need the user agent.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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