Make WordPress Core

Opened 15 years ago

Closed 15 years ago

#11120 closed defect (bug) (fixed)

Issue with ABSPATH already defined

Reported by: ontic's profile ontic Owned by:
Milestone: 3.0 Priority: normal
Severity: normal Version: 2.8.5
Component: General Keywords: has-patch
Focuses: Cc:

Description

A recent project of mine involved using Ajax and I noticed a problem when trying to include a couple of files.

"wordpress/wp-admin/admin.php"
"wordpress/wp-load.php"

I was acquiring the location of ABSPATH manually because the file I was working with had no involvement with any Wordpress files. Below is an example of how I was calculating the correct location.

"$path = rtrim(dirname(dirname(dirname(FILE))), '/').'/';"

So this enabled me to "require_once" the "admin.php" file. It was not necessary to include the "wp-load.php" file because "admin.php" does that itself.

Inside the file "admin.php" it includes the "wp-load.php" file like so.

if ( defined('ABSPATH') )

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

else

require_once('../wp-load.php');

In my case "wp-load.php" cannot be included because it has no idea of its location. When I tried defining ABSPATH myself, I then encounter another problem. Which can be overcome, by checking whether ABSPATH has already been defined in the file "wp-load.php" please see the attached patch.

Regards,
Adam

Attachments (1)

wp-load.php.patch (496 bytes) - added by ontic 15 years ago.
Patch for this ticket

Download all attachments as: .zip

Change History (10)

@ontic
15 years ago

Patch for this ticket

#1 @dd32
15 years ago

Your method of including wp-load is broken to start with.

$path = rtrim(dirname(dirname(dirname(FILE))), '/').'/';

will not always return the plugin directory, that directory can be moved easily.

If you require wordpress to be loaded, either use admin-ajax.php, admin-post.php, or access the frontpage directly, and hook upon 'init' to check for your flag being set, and handle the request yourself..

Theres been a lot of discussion around this recently, and a few tickets asking for a ajax front end handler.. (Which i'm in support of), But i'm -1 to making it easier for anyone to hook wordpress as such you're suggesting for the simple reason that it doesnt always work.. and makes things a pain in the bum for those who use that function of WordPress.

#2 @mikeschinkel
15 years ago

  • Cc mikeschinkel@… added

I've run into the same problem and need the same fix.

@dd32 I think your justification for why it shouldn't be fixed is flawed, at least in some cases. Just because he chose to use a poorly selected expression to get the $root doesn't make this patch any less valid.

I'm trying to load admin.php prior to calling any bootstrap code and for that I need to know the root directory in ABSPATH, for that I'm using:

define('ABSPATH',$_SERVER['DOCUMENT_ROOT'] .'/');

I believe this is a patch that is needed, especially considering how it is inconsistent when the code in admin.php that presumes that ABSPATH may already be defined and then precedes to call wp-load.php that assumes ABSPATH was not predefined.

The patch provided by @ontic is simple and can't cause an unexpected bug unless someone is doing something that would cause an error already.

#3 follow-up: @mikeschinkel
15 years ago

  • Version changed from 2.8.5 to 2.9

#4 @dd32
15 years ago

  • Keywords has-patch added
  • Milestone changed from Unassigned to 3.0

@dd32 I think your justification for why it shouldn't be fixed is flawed

My comments were NOT why it shouldnt be fixed. My comments were that his code he is using is flawed, Nor was it referencing his patch. I also suggested a few other ways of doing what he wanted to, in a more "Wordpressy" way.

I dont see any reason why the attached patch couldnt be commited, No harm in checking before defining it.

#5 in reply to: ↑ 3 @westi
15 years ago

  • Version changed from 2.9 to 2.8.5

Replying to mikeschinkel:

Please don't change the reported in version to a newer version.

Then we lose the history of when the bug was identified.

#6 @mikeschinkel
15 years ago

@dd32 - My comments were NOT why it shouldnt be fixed. My comments were that his code he is using is flawed, Nor was it referencing his patch.

Sorry... didn't mean to offend. But at least I hope you can understand how I misread by rereading your comments: "But i'm -1 to making it easier for anyone to hook wordpress as such you're suggesting for the simple reason that it doesnt always work."

@westi - Please don't change the reported in version to a newer version.

Sorry again. I misunderstood how you were using the version numbers.

#7 @westi
15 years ago

I think it might be easier and better to change admin.php to have a more successful way of locating wp-load.php for the require_once.

wp-load.php is always going to try and define ABSPATH and IMHO it should always do that itself as it knows for sure where ABSPATH is.

If we move to the wp-load.php require method used in install.php then we should always be able to find it from admin.php.

#8 @mikeschinkel
15 years ago

Sure, whatever works best. This was a tiny patch to solve a simple problem but if you've got a broader way to address the issue then that's even better.

#9 @westi
15 years ago

  • Resolution set to fixed
  • Status changed from new to closed

(In [12583]) Use a more reliable method of locating wp-load.php in the admin bootstrap. Fixes #11120.

Note: See TracTickets for help on using tickets.