[wp-trac] [WordPress Trac] #17092: use dirname(__file__).'/file.php' instead of './file' for includes

WordPress Trac wp-trac at lists.automattic.com
Sat Apr 9 12:57:36 UTC 2011


#17092: use dirname(__file__).'/file.php' instead of './file' for includes
-------------------------+-----------------------------------
 Reporter:  ketwaroo     |      Owner:
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  General      |    Version:  3.1.1
 Severity:  minor        |   Keywords:  has-patch 2nd-opinion
-------------------------+-----------------------------------
 most initial includes prior to having ABSPATH defined are usually of the
 format:

 {{{
 #!php
 require('./wp-blog-header.php');
 }}}

 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.

 for example:

 {{{
 #!php
 in /index.php
  require('./wp-blog-header.php');
 becomes:
  require( dirname(__FILE__) . '/wp-blog-header.php' );
 }}}
 {{{
 #!php
 in /wp-admin/admin-ajax.php
  require_once('../wp-load.php');
 becomes
  require_once( dirname(dirname(__FILE__)) . '/wp-load.php' );
 }}}
 {{{
 #!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.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/17092>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list