Discussion:
wp-config.php defining value of ABSPATH
Utkarsh Dixit
2014-02-09 13:58:21 UTC
Permalink
Hi,

I'm just a beginner to wordpress so it might sound a little naive, in
wp-config.php file we have following lines of code just before including
'wp-settings.php'

if ( !defined('ABSPATH') )
define('ABSPATH', dirname(__FILE__) . '/');


Seems useless to me as we already define ABSPATH in wp-blog-header.php and
suppose if we directly open our wp-config.php file then also if it is a
level above the wordpress root directory the ABSPATH is set to the
directory a level above the wordpress root directory which gives a fatal
error when we include the wp-settings.php file in the next step.Can't we do
it like this?

if ( !defined('ABSPATH') )
define('ABSPATH', dirname(__FILE__) . '/');

if(file_exists(ABSPATH . 'wp-settings.php'))
require_once(ABSPATH . 'wp-settings.php');


It helps in removing the Fatal error which might occur.
Nikola Nikolov
2014-02-09 15:46:25 UTC
Permalink
It's actually defined in wp-load.php and the correct way of including just
WordPress(without parsing the request and displaying the correct template)
is actually by including wp-load.php and not wp-config.php.

Basically wp-load.php looks in two locations for wp-config.php:

ABSPATH . 'wp-config.php'

and

dirname( ABSPATH ) . '/wp-config.php'

In the second case, wp-load.php also makes sure that in the directory where
the wp-config.php resides there is no wp-settings.php, because if there is,
that means that this wp-config file is actually part of a different
install.
Post by Utkarsh Dixit
Hi,
I'm just a beginner to wordpress so it might sound a little naive, in
wp-config.php file we have following lines of code just before including
'wp-settings.php'
if ( !defined('ABSPATH') )
define('ABSPATH', dirname(__FILE__) . '/');
Seems useless to me as we already define ABSPATH in wp-blog-header.php and
suppose if we directly open our wp-config.php file then also if it is a
level above the wordpress root directory the ABSPATH is set to the
directory a level above the wordpress root directory which gives a fatal
error when we include the wp-settings.php file in the next step.Can't we do
it like this?
if ( !defined('ABSPATH') )
define('ABSPATH', dirname(__FILE__) . '/');
if(file_exists(ABSPATH . 'wp-settings.php'))
require_once(ABSPATH . 'wp-settings.php');
It helps in removing the Fatal error which might occur.
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
Utkarsh Dixit
2014-02-09 16:00:04 UTC
Permalink
What I meant was let my wordpress be installed in a location like

http://example.com/web/wp/

but my wp-config.php file (not any other) is in

http://example.com/web/

folder, then if I open

http://example.com/web/wp-config.php

it will give a fatal error on the line :

require_once(ABSPATH . 'wp-settings.php');


because of the condition

if ( !defined('ABSPATH') )
define('ABSPATH', dirname(__FILE__) . '/');


Thanks for pointing out that it is defined in wp-load.php probably mixed
up the names (being still new to wordpress).
Post by Nikola Nikolov
It's actually defined in wp-load.php and the correct way of including just
WordPress(without parsing the request and displaying the correct template)
is actually by including wp-load.php and not wp-config.php.
ABSPATH . 'wp-config.php'
and
dirname( ABSPATH ) . '/wp-config.php'
In the second case, wp-load.php also makes sure that in the directory where
the wp-config.php resides there is no wp-settings.php, because if there is,
that means that this wp-config file is actually part of a different
install.
Post by Utkarsh Dixit
Hi,
I'm just a beginner to wordpress so it might sound a little naive, in
wp-config.php file we have following lines of code just before including
'wp-settings.php'
if ( !defined('ABSPATH') )
define('ABSPATH', dirname(__FILE__) . '/');
Seems useless to me as we already define ABSPATH in wp-blog-header.php
and
Post by Utkarsh Dixit
suppose if we directly open our wp-config.php file then also if it is a
level above the wordpress root directory the ABSPATH is set to the
directory a level above the wordpress root directory which gives a fatal
error when we include the wp-settings.php file in the next step.Can't we
do
Post by Utkarsh Dixit
it like this?
if ( !defined('ABSPATH') )
define('ABSPATH', dirname(__FILE__) . '/');
if(file_exists(ABSPATH . 'wp-settings.php'))
require_once(ABSPATH . 'wp-settings.php');
It helps in removing the Fatal error which might occur.
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
Nikola Nikolov
2014-02-09 16:01:09 UTC
Permalink
I'm still not sure why you would open wp-config.php :)
Post by Utkarsh Dixit
What I meant was let my wordpress be installed in a location like
http://example.com/web/wp/
but my wp-config.php file (not any other) is in
http://example.com/web/
folder, then if I open
http://example.com/web/wp-config.php
require_once(ABSPATH . 'wp-settings.php');
because of the condition
if ( !defined('ABSPATH') )
define('ABSPATH', dirname(__FILE__) . '/');
Thanks for pointing out that it is defined in wp-load.php probably mixed
up the names (being still new to wordpress).
Post by Nikola Nikolov
It's actually defined in wp-load.php and the correct way of including
just
Post by Nikola Nikolov
WordPress(without parsing the request and displaying the correct
template)
Post by Nikola Nikolov
is actually by including wp-load.php and not wp-config.php.
ABSPATH . 'wp-config.php'
and
dirname( ABSPATH ) . '/wp-config.php'
In the second case, wp-load.php also makes sure that in the directory
where
Post by Nikola Nikolov
the wp-config.php resides there is no wp-settings.php, because if there
is,
Post by Nikola Nikolov
that means that this wp-config file is actually part of a different
install.
Post by Utkarsh Dixit
Hi,
I'm just a beginner to wordpress so it might sound a little naive, in
wp-config.php file we have following lines of code just before
including
Post by Nikola Nikolov
Post by Utkarsh Dixit
'wp-settings.php'
if ( !defined('ABSPATH') )
define('ABSPATH', dirname(__FILE__) . '/');
Seems useless to me as we already define ABSPATH in wp-blog-header.php
and
Post by Utkarsh Dixit
suppose if we directly open our wp-config.php file then also if it is a
level above the wordpress root directory the ABSPATH is set to the
directory a level above the wordpress root directory which gives a
fatal
Post by Nikola Nikolov
Post by Utkarsh Dixit
error when we include the wp-settings.php file in the next step.Can't
we
Post by Nikola Nikolov
do
Post by Utkarsh Dixit
it like this?
if ( !defined('ABSPATH') )
define('ABSPATH', dirname(__FILE__) . '/');
if(file_exists(ABSPATH . 'wp-settings.php'))
require_once(ABSPATH . 'wp-settings.php');
It helps in removing the Fatal error which might occur.
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
Utkarsh Dixit
2014-02-09 16:02:14 UTC
Permalink
Yeah, that's that :)

Thanks.
Andrew Nacin
2014-02-09 16:07:24 UTC
Permalink
wp-load.php was new in WordPress 2.6 when we made it so you could put
WordPress in its own directory but leave wp-config.php outside of it (for
SVN externals & git submodules reasons). The include from wp-config.php is
there for backwards compatibility reasons, and yes obviously doesn't work
in this setup.

https://core.trac.wordpress.org/ticket/6933
Post by Utkarsh Dixit
What I meant was let my wordpress be installed in a location like
http://example.com/web/wp/
but my wp-config.php file (not any other) is in
http://example.com/web/
folder, then if I open
http://example.com/web/wp-config.php
require_once(ABSPATH . 'wp-settings.php');
because of the condition
if ( !defined('ABSPATH') )
define('ABSPATH', dirname(__FILE__) . '/');
Thanks for pointing out that it is defined in wp-load.php probably mixed
up the names (being still new to wordpress).
Post by Nikola Nikolov
It's actually defined in wp-load.php and the correct way of including
just
Post by Nikola Nikolov
WordPress(without parsing the request and displaying the correct
template)
Post by Nikola Nikolov
is actually by including wp-load.php and not wp-config.php.
ABSPATH . 'wp-config.php'
and
dirname( ABSPATH ) . '/wp-config.php'
In the second case, wp-load.php also makes sure that in the directory
where
Post by Nikola Nikolov
the wp-config.php resides there is no wp-settings.php, because if there
is,
Post by Nikola Nikolov
that means that this wp-config file is actually part of a different
install.
Post by Utkarsh Dixit
Hi,
I'm just a beginner to wordpress so it might sound a little naive, in
wp-config.php file we have following lines of code just before
including
Post by Nikola Nikolov
Post by Utkarsh Dixit
'wp-settings.php'
if ( !defined('ABSPATH') )
define('ABSPATH', dirname(__FILE__) . '/');
Seems useless to me as we already define ABSPATH in wp-blog-header.php
and
Post by Utkarsh Dixit
suppose if we directly open our wp-config.php file then also if it is a
level above the wordpress root directory the ABSPATH is set to the
directory a level above the wordpress root directory which gives a
fatal
Post by Nikola Nikolov
Post by Utkarsh Dixit
error when we include the wp-settings.php file in the next step.Can't
we
Post by Nikola Nikolov
do
Post by Utkarsh Dixit
it like this?
if ( !defined('ABSPATH') )
define('ABSPATH', dirname(__FILE__) . '/');
if(file_exists(ABSPATH . 'wp-settings.php'))
require_once(ABSPATH . 'wp-settings.php');
It helps in removing the Fatal error which might occur.
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
Utkarsh Dixit
2014-02-09 16:37:17 UTC
Permalink
@Andrew Nacin
Won't adding this condition be better?


if(file_exists(ABSPATH . 'wp-settings.php'))
require_once(ABSPATH . 'wp-settings.php');
Post by Andrew Nacin
wp-load.php was new in WordPress 2.6 when we made it so you could put
WordPress in its own directory but leave wp-config.php outside of it (for
SVN externals & git submodules reasons). The include from wp-config.php is
there for backwards compatibility reasons, and yes obviously doesn't work
in this setup.
https://core.trac.wordpress.org/ticket/6933
Post by Utkarsh Dixit
What I meant was let my wordpress be installed in a location like
http://example.com/web/wp/
but my wp-config.php file (not any other) is in
http://example.com/web/
folder, then if I open
http://example.com/web/wp-config.php
require_once(ABSPATH . 'wp-settings.php');
because of the condition
if ( !defined('ABSPATH') )
define('ABSPATH', dirname(__FILE__) . '/');
Thanks for pointing out that it is defined in wp-load.php probably mixed
up the names (being still new to wordpress).
Post by Nikola Nikolov
It's actually defined in wp-load.php and the correct way of including
just
Post by Nikola Nikolov
WordPress(without parsing the request and displaying the correct
template)
Post by Nikola Nikolov
is actually by including wp-load.php and not wp-config.php.
ABSPATH . 'wp-config.php'
and
dirname( ABSPATH ) . '/wp-config.php'
In the second case, wp-load.php also makes sure that in the directory
where
Post by Nikola Nikolov
the wp-config.php resides there is no wp-settings.php, because if there
is,
Post by Nikola Nikolov
that means that this wp-config file is actually part of a different
install.
On Sun, Feb 9, 2014 at 3:58 PM, Utkarsh Dixit <
Post by Utkarsh Dixit
Hi,
I'm just a beginner to wordpress so it might sound a little naive, in
wp-config.php file we have following lines of code just before
including
Post by Nikola Nikolov
Post by Utkarsh Dixit
'wp-settings.php'
if ( !defined('ABSPATH') )
define('ABSPATH', dirname(__FILE__) . '/');
Seems useless to me as we already define ABSPATH in
wp-blog-header.php
Post by Utkarsh Dixit
Post by Nikola Nikolov
and
Post by Utkarsh Dixit
suppose if we directly open our wp-config.php file then also if it
is a
Post by Utkarsh Dixit
Post by Nikola Nikolov
Post by Utkarsh Dixit
level above the wordpress root directory the ABSPATH is set to the
directory a level above the wordpress root directory which gives a
fatal
Post by Nikola Nikolov
Post by Utkarsh Dixit
error when we include the wp-settings.php file in the next step.Can't
we
Post by Nikola Nikolov
do
Post by Utkarsh Dixit
it like this?
if ( !defined('ABSPATH') )
define('ABSPATH', dirname(__FILE__) . '/');
if(file_exists(ABSPATH . 'wp-settings.php'))
require_once(ABSPATH . 'wp-settings.php');
It helps in removing the Fatal error which might occur.
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
Andrew Nacin
2014-02-09 16:53:52 UTC
Permalink
That's a wasted stat call to see if the file exists. If the constant is
already defined (as it should be, if wp-load.php is the entry point), then
nothing will happen. If wp-config.php is somehow the entry point and WP
isn't in a subdirectory (by far most common), then it'll still work (this
is the back compat).
Post by Utkarsh Dixit
@Andrew Nacin
Won't adding this condition be better?
if(file_exists(ABSPATH . 'wp-settings.php'))
require_once(ABSPATH . 'wp-settings.php');
Post by Andrew Nacin
wp-load.php was new in WordPress 2.6 when we made it so you could put
WordPress in its own directory but leave wp-config.php outside of it (for
SVN externals & git submodules reasons). The include from wp-config.php
is
Post by Andrew Nacin
there for backwards compatibility reasons, and yes obviously doesn't work
in this setup.
https://core.trac.wordpress.org/ticket/6933
Post by Utkarsh Dixit
What I meant was let my wordpress be installed in a location like
http://example.com/web/wp/
but my wp-config.php file (not any other) is in
http://example.com/web/
folder, then if I open
http://example.com/web/wp-config.php
require_once(ABSPATH . 'wp-settings.php');
because of the condition
if ( !defined('ABSPATH') )
define('ABSPATH', dirname(__FILE__) . '/');
Thanks for pointing out that it is defined in wp-load.php probably
mixed
Post by Andrew Nacin
Post by Utkarsh Dixit
up the names (being still new to wordpress).
Post by Nikola Nikolov
It's actually defined in wp-load.php and the correct way of including
just
Post by Nikola Nikolov
WordPress(without parsing the request and displaying the correct
template)
Post by Nikola Nikolov
is actually by including wp-load.php and not wp-config.php.
ABSPATH . 'wp-config.php'
and
dirname( ABSPATH ) . '/wp-config.php'
In the second case, wp-load.php also makes sure that in the directory
where
Post by Nikola Nikolov
the wp-config.php resides there is no wp-settings.php, because if
there
Post by Andrew Nacin
Post by Utkarsh Dixit
is,
Post by Nikola Nikolov
that means that this wp-config file is actually part of a different
install.
On Sun, Feb 9, 2014 at 3:58 PM, Utkarsh Dixit <
Post by Utkarsh Dixit
Hi,
I'm just a beginner to wordpress so it might sound a little naive,
in
Post by Andrew Nacin
Post by Utkarsh Dixit
Post by Nikola Nikolov
Post by Utkarsh Dixit
wp-config.php file we have following lines of code just before
including
Post by Nikola Nikolov
Post by Utkarsh Dixit
'wp-settings.php'
if ( !defined('ABSPATH') )
define('ABSPATH', dirname(__FILE__) . '/');
Seems useless to me as we already define ABSPATH in
wp-blog-header.php
Post by Utkarsh Dixit
Post by Nikola Nikolov
and
Post by Utkarsh Dixit
suppose if we directly open our wp-config.php file then also if it
is a
Post by Utkarsh Dixit
Post by Nikola Nikolov
Post by Utkarsh Dixit
level above the wordpress root directory the ABSPATH is set to the
directory a level above the wordpress root directory which gives a
fatal
Post by Nikola Nikolov
Post by Utkarsh Dixit
error when we include the wp-settings.php file in the next
step.Can't
Post by Andrew Nacin
Post by Utkarsh Dixit
we
Post by Nikola Nikolov
do
Post by Utkarsh Dixit
it like this?
if ( !defined('ABSPATH') )
define('ABSPATH', dirname(__FILE__) . '/');
if(file_exists(ABSPATH . 'wp-settings.php'))
require_once(ABSPATH . 'wp-settings.php');
It helps in removing the Fatal error which might occur.
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
Utkarsh Dixit
2014-02-09 16:55:29 UTC
Permalink
Hmmmm, I get it now

Thanks.
Post by Andrew Nacin
That's a wasted stat call to see if the file exists. If the constant is
already defined (as it should be, if wp-load.php is the entry point), then
nothing will happen. If wp-config.php is somehow the entry point and WP
isn't in a subdirectory (by far most common), then it'll still work (this
is the back compat).
Post by Utkarsh Dixit
@Andrew Nacin
Won't adding this condition be better?
if(file_exists(ABSPATH . 'wp-settings.php'))
require_once(ABSPATH . 'wp-settings.php');
Post by Andrew Nacin
wp-load.php was new in WordPress 2.6 when we made it so you could put
WordPress in its own directory but leave wp-config.php outside of it
(for
Post by Utkarsh Dixit
Post by Andrew Nacin
SVN externals & git submodules reasons). The include from wp-config.php
is
Post by Andrew Nacin
there for backwards compatibility reasons, and yes obviously doesn't
work
Post by Utkarsh Dixit
Post by Andrew Nacin
in this setup.
https://core.trac.wordpress.org/ticket/6933
Post by Utkarsh Dixit
What I meant was let my wordpress be installed in a location like
http://example.com/web/wp/
but my wp-config.php file (not any other) is in
http://example.com/web/
folder, then if I open
http://example.com/web/wp-config.php
require_once(ABSPATH . 'wp-settings.php');
because of the condition
if ( !defined('ABSPATH') )
define('ABSPATH', dirname(__FILE__) . '/');
Thanks for pointing out that it is defined in wp-load.php probably
mixed
Post by Andrew Nacin
Post by Utkarsh Dixit
up the names (being still new to wordpress).
On Sun, Feb 9, 2014 at 9:16 PM, Nikola Nikolov <
Post by Nikola Nikolov
It's actually defined in wp-load.php and the correct way of
including
Post by Utkarsh Dixit
Post by Andrew Nacin
Post by Utkarsh Dixit
just
Post by Nikola Nikolov
WordPress(without parsing the request and displaying the correct
template)
Post by Nikola Nikolov
is actually by including wp-load.php and not wp-config.php.
ABSPATH . 'wp-config.php'
and
dirname( ABSPATH ) . '/wp-config.php'
In the second case, wp-load.php also makes sure that in the
directory
Post by Utkarsh Dixit
Post by Andrew Nacin
Post by Utkarsh Dixit
where
Post by Nikola Nikolov
the wp-config.php resides there is no wp-settings.php, because if
there
Post by Andrew Nacin
Post by Utkarsh Dixit
is,
Post by Nikola Nikolov
that means that this wp-config file is actually part of a different
install.
On Sun, Feb 9, 2014 at 3:58 PM, Utkarsh Dixit <
Post by Utkarsh Dixit
Hi,
I'm just a beginner to wordpress so it might sound a little
naive,
Post by Utkarsh Dixit
in
Post by Andrew Nacin
Post by Utkarsh Dixit
Post by Nikola Nikolov
Post by Utkarsh Dixit
wp-config.php file we have following lines of code just before
including
Post by Nikola Nikolov
Post by Utkarsh Dixit
'wp-settings.php'
if ( !defined('ABSPATH') )
define('ABSPATH', dirname(__FILE__) . '/');
Seems useless to me as we already define ABSPATH in
wp-blog-header.php
Post by Utkarsh Dixit
Post by Nikola Nikolov
and
Post by Utkarsh Dixit
suppose if we directly open our wp-config.php file then also if
it
Post by Utkarsh Dixit
Post by Andrew Nacin
is a
Post by Utkarsh Dixit
Post by Nikola Nikolov
Post by Utkarsh Dixit
level above the wordpress root directory the ABSPATH is set to
the
Post by Utkarsh Dixit
Post by Andrew Nacin
Post by Utkarsh Dixit
Post by Nikola Nikolov
Post by Utkarsh Dixit
directory a level above the wordpress root directory which gives
a
Post by Utkarsh Dixit
Post by Andrew Nacin
Post by Utkarsh Dixit
fatal
Post by Nikola Nikolov
Post by Utkarsh Dixit
error when we include the wp-settings.php file in the next
step.Can't
Post by Andrew Nacin
Post by Utkarsh Dixit
we
Post by Nikola Nikolov
do
Post by Utkarsh Dixit
it like this?
if ( !defined('ABSPATH') )
define('ABSPATH', dirname(__FILE__) . '/');
if(file_exists(ABSPATH . 'wp-settings.php'))
require_once(ABSPATH . 'wp-settings.php');
It helps in removing the Fatal error which might occur.
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
Loading...