[wp-hackers] find wp-config from a plugin file
Jacob Santos
wordpress at santosj.name
Tue Jan 29 13:46:00 GMT 2008
Kimmo Suominen wrote:
> On Tue, Jan 29, 2008 at 07:12:59AM -0600, Jacob Santos wrote:
>
>> require_once( realpath( dirname(__FILE__) .'/../../wp_config.php');
>>
>
> Why not just
>
> require_once( '../../wp-config.php');
>
> The dirname() and realpath() calls are not needed, as far as I can
> tell.
>
> Using require_once inside a strictly proceted with relative paths is
> ok, as long as you don't mix something like this:
>
> require_once( '../../wp-config.php');
> require_once( './../../wp-config.php');
> require_once( '././../../wp-config.php');
>
> In other words, leading "./" is going to be problematic and isn't
> needed with WordPress. WordPress already uses include statements
> without a leading dot directory, and in my humble opinion should
> get rid of the few include statements with leading single dot
> directories. This would make it work within a directory tree
> where the whole path to the root directory (on a UNIX system) is
> not readable (only executable, i.e. searchable).
>
> Calling realpath() is another problem for strict permissions and
> in every case I've seen in WordPress, completely unnecessary.
>
> Best regards,
> + Kimmo
>
True, that. In several projects, I just use which ever method pleases my
eye at the time. However, I don't use relative paths such as those. As
with WordPress, there are some safe mode issues (possible or whatever).
It /is/ my convention to always use
dirname(__FILE__).'/whatever/to/path'; However, a co-worker uses your
method just fine. This is just one of those convention things that has
no real end debate, so use whatever pleases you.
The reason you would use realpath, for your information, is so your path
doesn't look like: "Path/to/folder/../wp_config.php" which looks
terrible. If you use realpath, it removes the folder and ../ and looks
tons prettier. It also has the advantage of not giving you the path if
the file doesn't exist. However, realpath also has overhead which is
best not used.
However, I can't understand using dirname() multiple times, because the
call just adds unnecessary overhead.
I think all of these are reasons why 'ABSPATH' exists.
--
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