Closed jenkoian closed 4 years ago
This also relates to https://github.com/woocommerce/wc-smooth-generator/pull/19
Any feedback on this? Alternatively make this library available as something installable via wp package install
rather than a plugin??
@jenkoian Thanks for submitting the PR. It is generally a discouraged practice to load PHP files outside of a plugin's directory unless that file is maintained by the plugin. The readme on the site-stack
project has [nstructions for adding autoload.php
to the site's configuration (under Autoload heading).
You could make smooth generator compatible with that setup by adding a file and a class exist check to the plugin load sequence.
@jenkoian #40 implements my recommendation above so I'll close this PR.
That works, thanks!
Currently the assumption is that the vendor library will be installed relative to the main plugin file, i.e. $plugin_dir/vendor, however there are lots of instances where this may not be the case.
One common use case is for
vendor
to be relative towp-content
such as is the case when following a composer in wordpress recipe such as this one: https://composer.rarst.net/recipe/site-stack/ therefore it makes sense to check if the vendor and thus autoload file is in here first.Taking this a bit further, there's a (mostly) unwritten convention which is to use an env var to mark the composer vendor dir (see discussion here: https://github.com/composer/composer/issues/2904) so it makes sense to check if that exists first.
There may also be cases where developers are storing vendors in the project root or one level above but not using WP_CONTENT_DIR constant so makes sense to check there too.
So this will check all of the above and can be summed up as thus:
Check for vendor directory in the following: