woocommerce-gateway-stripe icon indicating copy to clipboard operation
woocommerce-gateway-stripe copied to clipboard

fix: WC_STRIPE_PLUGIN_URL when pointing to symbolic link

Open dkoo opened this issue 11 months ago • 0 comments

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

  1. 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).
  2. In your test environment's shell environment, cd into the wp-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
  3. 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.
  4. While on develop, visit your site's front-end and observe that the WC_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
  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.
  2. 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 and readme.txt (or does not apply)
  • [ ] Tested on mobile (or does not apply)

Post merge

dkoo avatar Mar 28 '24 20:03 dkoo