[wp-hackers] "deprecating" direct calls to wp-config.php

Stephen Rider wp-hackers at striderweb.com
Tue Nov 3 17:57:16 UTC 2009

On Nov 3, 2009, at 11:05 AM, Otto wrote:

> On Tue, Nov 3, 2009 at 9:43 AM, Claudio Simeone <mrbrog at gmail.com>  
> wrote:
>> Sometimes I include wp-load.php in scripts external to WP....
>> Is that correct, or is to be discouraged, and if so, what is the
>> correct way to use WP environment in external scripts?
> The correct way depends on what exactly you're doing. However, there's
> never any real reason to include wp-config or wp-load directly. Doing
> so is.. not wrong, exactly... just a bit sloppy. It's error-prone,
> more likely to break things.

A little more specifically, as of WP 2.6, wp-config.php may be one  
directory up from where you expect it, which can break things.  Not  
only will you plugin be looking for a file that isn't there, but if a  
moved wp-config.php sets ABSPATH, ABSPATH will be *wrong*.

Thus if you absolutely must call one of these directly, call wp- 
load.php as it doesn't ever move.

Beyond that, Otto's advice is good. :)

> For most anything else, hooking into the template_redirect function to
> produce your custom output is the better way to go.


Stephen Rider

More information about the wp-hackers mailing list