strangerstudios / paid-memberships-pro

The Trusted Membership Platform That Grows with You: Restrict access to content and charge recurring subscriptions using Stripe, PayPal, and more. Fully open source. 100% GPL.
https://www.paidmembershipspro.com
Other
469 stars 359 forks source link

Bad path to wp-load.php #61

Closed chrisvanpatten closed 8 years ago

chrisvanpatten commented 11 years ago
Warning: require_once(/home/content/67/10323067/html/content/plugins/paid-memberships-pro/services/../../../../wp-load.php) [function.require-once]: failed to open stream: No such file or directory in /home/content/67/10323067/html/content/plugins/paid-memberships-pro/services/applydiscountcode.php on line 9

Fatal error: require_once() [function.require]: Failed opening required '/home/content/67/10323067/html/content/plugins/paid-memberships-pro/services/../../../../wp-load.php' (include_path='.:/usr/local/php5_3/lib/php') in /home/content/67/10323067/html/content/plugins/paid-memberships-pro/services/applydiscountcode.php on line 9

We keep wp-load.php at site.com/wp/wp-load.php, not site.com/wp-load.php, as part of our wpframe setup, so the relative path you use here doesn't work properly.

chrisvanpatten commented 11 years ago

I'm googling around to try to find some kind of constant or function that reliably gets the path to WP root, but coming up empty. There has to be some kind of clever way around this though... I hope?

strangerstudios commented 11 years ago

Hmmm. That loading of wp-load.php in there is in case you want to access the script directly as some older setups of PMPro do. If you access sitename.com/wp-admin/admin-ajax.php?action=applydiscountcode (see https://github.com/strangerstudios/paid-memberships-pro/blob/dev/includes/services.php#L8) it should load WP without having to hit that code.

Perhaps an old template (StripeLite?) is still trying to access the script directly. FYI, I am planning on incorporating the Stripe Lite functionality into the core plugin so it doesn't have to load it's own templates, etc.

chrisvanpatten commented 11 years ago

Currently using PayPal Standard. I'll take another look but I don't think we're doing anything with special templates or anything like that.

chrisvanpatten commented 11 years ago

I looked into this and right now we're using all PMPro default templates (modified in a few places through random hooks here and there).

What would be calling the applydiscountcode.php file?

I want to make sure this gets fixed before the next PMPro update, so I don't have to keep logging in and tweaking the file after every update. :)

chrisvanpatten commented 11 years ago

Okay, it looks like paid-memberships-pro/pages/checkout.php (lines 127, 129, 592, & 594) talks to paid-memberships-pro/includes/services.php which loads paid-memberships-pro/services/applydiscountcode.php (lines 6–15). This is all stuff you probably know. (I'm talking it out mostly for my own understanding.)

When applydiscountcode.php is loaded, it checks to see if WP_USE_THEMES is true or false; if true, it is supposed to move on, and if false it brings in wp-load.php. For whatever reason, my site is returning false here, on this AJAX call. Here's the error:

Failed to load resource: the server responded with a status of 500 (Internal Server Error)
https://www.coachmenyc.com/wp/wp-admin/?action=applydiscountcode&code=CVPTEST&level=1&msgfield=pmpro_message

So what I'm noticing here is that the URL it's calling to is https://www.coachmenyc.com/wp/wp-admin/?action=applydiscountcode instead of https://www.coachmenyc.com/wp/wp-admin/admin-ajax.php?action=applydiscountcode.

Could the lack of admin-ajax.php in that URL be the source of the problem? And if so, why's it doing that in the first place?

(And, further, could this have an impact on #60 as well?)

strangerstudios commented 11 years ago

Just writing to say that I saw this and will try to address it. It could be related to #60.

When doing ajaxy/service type things, it's a tricky decision on whether to use admin-ajax.php or go through another WP page and just pass a parameter and then if you want to do it on your homepage vs /wp-admin/. It mostly revolves around how much of WP has loaded in each of those cases and what filters/etc are available.

I don't remember off the top of my head why I chose to go through /wp-admin/ instead of /wp-admin/admin-ajax.php in these cases. I get the sense that one way breaks some setups and customizations and the other way breaks other setups, etc.

Does going through admin-ajax.php fix the server error for you?

BTW, The next version of PMPro removes the need for the Stripe Lite plugin (it's just an option on the payment settings page now). Not sure if you caught that.

chrisvanpatten commented 10 years ago

Hey, any word on this error and #60? They seem to be tightly related and it's causing a lot of errors for a client install of PMPro.

solhuebner commented 10 years ago

Is this still an issue as #60 is closed?

retlehs commented 9 years ago

yep, still an issue. any install that has wordpress in a subdirectory is broken.

https://github.com/strangerstudios/paid-memberships-pro/search?utf8=%E2%9C%93&q=wp-load

ref: http://ottopress.com/2010/dont-include-wp-load-please/

kalenjohnson commented 9 years ago

I've run into a very strange issue after having successfully gotten PMPro set up on a site with WP in a sub-directory.

As soon as I added discount codes to checkout, I was getting a popup with "Error applying discount". Following the trail, discount codes make an AJAX call to admin-ajax.php: https://github.com/strangerstudios/paid-memberships-pro/blob/dev/pages/checkout.php#L136

Which loads services/applydiscountcode.php: https://github.com/strangerstudios/paid-memberships-pro/blob/dev/includes/services.php#L8-L16

I'm pretty sure that admin-ajax.php calls does NOT set WP_USE_THEMES: https://github.com/strangerstudios/paid-memberships-pro/blob/dev/services/applydiscountcode.php#L6-L10

So because of that, wp-load.php is trying to be loaded. Which is already included in admin-ajax.php, but since it's a missing file if WP is installed in a sub-directory, it always errors.

Not sure of the best fix for this. Perhaps each of these "service" php files should also check for DOING_AJAX ?

strangerstudios commented 8 years ago

Cleaning up old issues. Thanks again @mathieuhays for fixing this here https://github.com/strangerstudios/paid-memberships-pro/issues/264

If anyone is still having related issues here, please open a new issue. Thanks.