[wp-hackers] wp-config.php, wp-load.php, and ABSPATH

Otto otto at ottodestruct.com
Thu Sep 10 13:58:26 UTC 2009

On Wed, Sep 9, 2009 at 4:35 PM, Stephen Rider <wp-hackers at striderweb.com> wrote:
> A problem that arises is plugins that do sort of "stand alone" things but
> want to access the database -- a common thing to do is to call wp-config.php
> directly to get the login info, rather than wp-load.php.  Again, this is
> unstable because wp-config.php may have moved, and even if the plugin
> correctly knows to look up a directory, it will get tripped up if it then
> tries to call another file and bases the path off of ABSPATH.
> While plugin authors *can* just call wp-load.php, which is safer and more
> stable, it appears to be quite common to do it the other way.

We'd had this basic discussion before.

Short answer is that plugins should not do that.

Long answer is that plugins that want to do "stand alone" sort of
things need to stop thinking they are stand alone and work within the
WordPress framework. We have hooks for most types of things (AJAX
calls and such) and we have methods to do other types of things
(template overload hooks), and those methods all work through the
framework. Thus, they have WordPress loaded, and you don't need to
include squat.

In conclusion, if you make your output directly call a separate file
in your plugin, and that file needs access to the database, then
*you're doing it wrong*. You can do it within the framework, and it's
generally much easier.

Give me a specific example, and I'll be glad to tell you the "right"
way that example should work. :)

Sent from Memphis, TN, United States

More information about the wp-hackers mailing list