woocommerce-gateway-stripe
woocommerce-gateway-stripe copied to clipboard
fix: WC_STRIPE_PLUGIN_URL when pointing to symbolic link
Changes proposed in this Pull Request:
Description: Fixes an esoteric bug that only seems to happen when the plugin is installed in a server location that is both unavailable for public HTTP requests and then symlinked to the wp-content/plugins
folder. Some hosts have a directory structure like this in order to manage plugin versions across multiple sites from a single server directory.
In this scenario, the WC_STRIPE_PLUGIN_URL
constant will include the path to the inaccessible server directory instead of the wp-content/plugins
directory, potentially resulting in 400 errors when fetching CSS and JS assets using this constant. The resulting errors break user-facing functionality at the point of checkout.
Not sure how this could be unit-tested, but open to adding if you think it's necessary.
Testing instructions
- In your test environment, install the plugin in a location where WordPress can't access it via HTTP, but your local environment can. (For example, if using a Docker environment, install it somewhere on the host machine outside of where the Docker container can access the file. This isn't a requirement, but will make the bug more apparent.) Name the plugin directory something different, such as the version number of the plugin (e.g.
8.0.1
). - In your test environment's shell environment,
cd
into thewp-content/plugins
directory and create a symbolic link to the "true" location of the plugin:ln -s <absolute path to source directory>/8.0.1 woocommerce-gateway-stripe
- If you want to see the constant in action, you can add a
var_dump( WC_STRIPE_PLUGIN_URL );
after line 31 of./woocommerce-gateway-stripe.php
. - While on
develop
, visit your site's front-end and observe that theWC_STRIPE_PLUGIN_URL
constant points to the source directory's parent directory instead of the symlinked directory:
https://<site URL>/wp-content/plugins/8.0.1
- If the source directory isn't accessible to WordPress, try to check out using the Stripe Gateway and see that you can't complete the transaction due to missing JS and CSS assets.
- Apply the patch in this PR and repeat, and confirm that the constant now contains the symlinked folder location (
https://<site URL>/wp-content/plugins/woocommerce-gateway-stripe
) and that you can now complete checkout on the front-end.
- [ ] Covered with tests (or have a good reason not to test in description ☝️)
- [ ] Added changelog entry in both
changelog.txt
andreadme.txt
(or does not apply) - [ ] Tested on mobile (or does not apply)
Post merge
- [ ] Added testing instructions to the Release Testing Instructions wiki page (or does not apply)