[wp-hackers] find wp-config from a plugin file

Jacob Santos wordpress at santosj.name
Tue Jan 29 13:12:59 GMT 2008


Pixline wrote:
> Hi all,
>
> first thing, I'd like to introduce you to the new alpha version of 
> Gengo [0], ported to WordPress 2.3. Now it almost works! :-)
>
> Afther that: if the plugin file is loaded as ajax it needs to know the 
> ABSPATH, and the original author did it like this:
>
> if (!defined('ABSPATH'))
> require_once(dirname(dirname(dirname(dirname(__FILE__)))) . 
> '/wp-config.php');
>
> this usually works, but don't work if wordpress is installed in a 
> different way, as you can see in [1]. There's a better and safer way 
> to find that file? I can't find anything better...
>
> By the way, if some of you can get in touch with Jamie Talbot please 
> teach me how to do it, I'm trying since october without success. While 
> I'm getting embarassed by this fork-that-is-not-a-fork, I'd love to 
> talk with him and maybe merge our effort with the regular codebase on 
> wordpress.org. But I couldn't find a working email address.. :-|
>
> Thank you!
> Paolo
>
> [0] http://code.google.com/p/gengo-wp23/
> [1] http://code.google.com/p/gengo-wp23/issues/detail?id=34
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
I finally understood what purpose having more than one dirname() has and 
well you don't need it. The same can be solved doing this: <?php 
require_once( realpath( dirname(__FILE__) .'/../../wp_config.php'); ?>. 
I would have to suggest that you first check whether the file exists two 
folders above you and if it doesn't, then check if it is three folders 
above you. However, since ABSPATH can be anywhere in relation to where 
your plugin is, I would say, just record ABSPATH and just call that path 
for AJAX. It would add some overhead, but you'll be right every time. 
Not sure how the user will feel having their full path stored in the 
database though. I wouldn't mind myself.

What in the WordPress API, do you need?

Jacob Santos

-- 

Jacob Santos

http://www.santosj.name - blog
http://funcdoc.wordpress.com - WordPress Documentation Blog/Guide Licensed under GPLv2

Also known as darkdragon and santosj on WP trac.



More information about the wp-hackers mailing list