0

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 ..


Update

ok Ok It Works !

I used

add_action('init', 'process');

function process() {
    if(!isset($_GET['goaction'])) return;
    if($_GET['goaction']=='process')
    include("godownload.php");
}
1

1 Answer 1

0

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

2
  • This is getting complicated for me. I can not find documentation on "wp_loaded" so I'm lost with that function
    – Alexander
    Commented Feb 25, 2013 at 4:32
  • @Alexander Does this answer help?
    – fuxia
    Commented Feb 25, 2013 at 10:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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