[wp-hackers] ajax and $wpdb

Eric Marden wp at xentek.net
Thu Jul 30 03:01:38 UTC 2009

> you can't guarantee the relative location
> of wp-load.php to your plugin files (they might have moved wp-content
> outside the main WP files, etc, etc)...

On Jul 29, 2009, at 2:45 PM, Silverstein, Jesse wrote:
> Re: Simon's problem of plugin directory location & editing plugin  
> files:
> I think if your plugin file has loaded, it's safe to assume that  
> ABSPATH has been defined, and you can go from there.

ABSPATH is only created for you if wp-load.php is called. If you're  
sending some processing out to userland, you may need to carry that  
path around with you. Like Simon noted if you move your WP files  
around to nonstandard places, you can't be sure where wp-load.php is,  
and hence will not have any CONSTANTS defined when you need them. One  
(sort of) inelegant solution is to wrap your JS file in a PHP script  
and pass the path into to dynamically write your ajax URLs therein.

I've been bitten by this since I put WP in its own folder via  
svn:externals, move my wp-content folder elsewhere and do other custom  
stuff in my set-up. If for some reason wp-load.php needs to be  
included directly into another script (in a plugin, ajax endpoint,  
etc) and the code depends on wp-load.php to be relative to wp-content,  
then you run into troubles.

There is more than one plugin that won't work with my custom set-up  
because of this very issue. I haven't found a good work around to this  

- Eric Marden

More information about the wp-hackers mailing list