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'm coding a plugin. One particular file of this plugin is supposed to pull data from the plugin's custom DB table, and output it with minimal processing as raw XML.

The problem is, to get the WPDB class to work when the file was opened directly, I had to add a require to wp-blog-header.php. This worked great BUT it turns out that including the file outputs the tags < html>, < head>, and < body>, which kinda screws up certain parts of the XML.

Is there any way I can [A] Suppress the tag-spitting behavior of wp-blog-header.php? [B] Get WPDB working in some other way?

Or should I just not use WPDB for DB access in this file in the plugin?

EDIT: False alarm. Firefox was adding the tags at the user's end, not Wordpress. Sorry for raising a big stink.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Include wp-load.php, not wp-blog-header.php. Better yet, hook onto the execution of a standard WordPress request and die early.

isset( $_GET['my_conditional_check'] ) && add_action( 'plugins_loaded', 'my_xml_output' );
function my_xml_output()
{
    // do my stuff
    exit;
}

This'll run WordPress, then my_xml_output(), then die before the request is actually parsed & the template is loaded/rendered:

http://example.com/?my_conditional_check
share|improve this answer
1  
Look into adding a feed with add_feed instead. Might fit the need better. –  Otto Jul 31 '12 at 23:17
    
Thanks for all your help. After the phantom < html> tags refused to go away, I finally got wireshark. Turns out they're being added by Firefox (at this end). On the bright side, your solution works better than mine did before. –  SoItBegins Aug 1 '12 at 0:13

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.