WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have made a Wordpress Plugin that is a kind of Download Manager. I have a external file download.php that is responsible for making downloads. This file is away of environment Wordpress, for this reason I must called:

$wp_root = dirname(dirname(dirname(dirname(__FILE__))));
require_once $wp_root.'/wp-load.php';

and I can use $wpdb for my sql query.

Note: This file must be external because I use functions "headers()" for force the download.

header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: ".$ctype);
header("Content-Length: ".$size);
header("Content-Disposition: attachment; filename=".$info->url_file);
header("Content-Transfer-Encoding: binary");

My plugin works great!, But when I want to publish it on the Wordpress repository, they answered me that it is forbidden to directly call wp-load.php or wp-config.php

Including wp-config.php and / or wp-load.php is not a good idea and we cannot approve a plugin that does so unless it has a very good reason to load the file(s). It is prone to failure since not all WordPress installs have the exact same file structure.

I don't know that use for I can use $wpbd

Note2: For download I first validate it with the DB, then download.

This is my plugin -> http://demo.gopymes.pe/social-godownload/

Update Sunday 24 febrary 2013

This is getting complicated for me. I can not find documentation on "wp_loaded" so I'm lost with that function.

I tested "template_redirect" but I realized that's not what I want, because redirects the document to download and I do not want the user to know where is located the document to download.

I was reviewing the plugin "DownloadMonitor" and oddly have the same mistake I did, include "wp-load.php" and "wp-login.php" in download.php, however they are in the Wordpress's repository and I do not leave.

Well, keep looking ..


ok Ok It Works !

I used

add_action('init', 'process');

function process() {
    if(!isset($_GET['goaction'])) return;
share|improve this question
Please, read this guidelines about Multi-posting. – brasofilo Feb 20 '13 at 22:41
up vote 0 down vote accepted

To send HTTP headers just do it early enough. On the action wp_loaded for example. Don’t forget to call exit; when you are done, so WordPress doesn’t send its own headers later.

See also How to Rewrite Wordpress URL for a Plugin

share|improve this answer
This is getting complicated for me. I can not find documentation on "wp_loaded" so I'm lost with that function – Alexander Feb 25 '13 at 4:32
@Alexander Does this answer help? – toscho Feb 25 '13 at 10:38
Yes! Thank you ! – Alexander Feb 25 '13 at 15:39

Your Answer


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.