I’m creating a plugin with an admin page that needs to:
- stream a file for download (set content-type & other headers)
- display HTML without the admin menu etc
In both of these cases the ‘pages’ must be accessible only to logged in administrators. So far I’ve found one way to accomplish both of these, by including wp-blog-header.php in a php file, checking the user is an admin and doing things myself from then on, as below.
require('../../../wp-blog-header.php');
if (!current_user_can('administrator'))
{
wp_die( __('You do not have sufficient permissions to access this page.') );
}
...set headers & stream file
Is there a better way of doing this?
Is there any reason I shouldn’t do it this way?
Thanks 🙂
I’ve done this two ways:
1) – a csv export function – detect that special content type handling is required BEFORE wp outputs anything.
Another way was more feed oriented, but same principle, except wp does the special handling detection (checks for ?feed=ics or ). Put the add_feed code in an init action.
function ‘ical_feed’ then does the whole header etc.
Take a look at the WordPress HTTP API.
http://core.trac.wordpress.org/browser/tags/3.3.2/wp-includes/http.php
As far as the rest of plugin development. Read the plugin API or about writing a plugin.