use dirname(__file__).'/file.php' instead of './file' for includes
|Reported by:||ketwaroo||Owned by:||nacin|
most initial includes prior to having ABSPATH defined are usually of the format:
as seen in the main index.php. Most of these occur in /wp-admin.
which is fine in most cases. Except on some windows servers where relative paths can get a bit funky. or if you're trying to include the file which contains a relative include in a file found in another directory (which happens when you're trying to use wordpress for something other than its intended purpose, like developing a more practical multisite system, on multiple domains, with a single copy of wordpress files for all the sites).
anyway, I just wanted to request that absolute paths be used for includes.
in /index.php require('./wp-blog-header.php'); becomes: require( dirname(__FILE__) . '/wp-blog-header.php' );
in /wp-admin/admin-ajax.php require_once('../wp-load.php'); becomes require_once( dirname(dirname(__FILE__)) . '/wp-load.php' );
in /wp-admin/maint/repair.php require_once('../../wp-load.php'); becomes require_once( dirname(dirname(dirname(__FILE__))) . '/wp-load.php' );
it may not look as pretty but I think it's a saner/safer method of inclusion. Just a suggestion for the next major release. Or as you gradually update files.
Attached is the patch I made from 3.1.1. It replaces every relative include|require(_once)? by absolute ones. As far as I've tested, works the same as unpatched and no includes are broken.
Change History (21)
comment:15 @nacin — 2 years ago
- Owner set to nacin
- Resolution set to fixed
- Status changed from new to closed