thom4parisot / wp-less

WordPress plugin which seemlessly compiles, caches and rebuilds your LESS stylesheets.
https://wordpress.org/plugins/wp-less/
88 stars 40 forks source link

Autoloading classes and adding a dependency free plugin loader #103

Closed mrgrain closed 7 years ago

mrgrain commented 8 years ago

Added the theme bootstrap file to composer autoload section. Thus this package can be truly used a dependency.

Fix for issue #102

mrgrain commented 8 years ago

I am sorry, this doesn't work out as easy as I thought it would. I'll look into it and open the PR again.

mrgrain commented 8 years ago

As pointed out in issue #102, the current plugin loader depends on the file path to the package. This is perfectly fine for most cases, but will break the workflow when using more sophisticated boilerplates like Bedrock.

This PR fixes those problems by

Nothing changes if this package is used...

However it will provide a new option for other plugins or themes bundling the package. Instead of including bootstrap-for-theme.php, they might now rely on composers autloader and kickstart the plugin with a simple dependency free method (use of the closure is optional):

$WPLessPlugin = \WPLessPluginLoader::load(function(WPLessPlugin ) {
    // they might add some actions here
    // add_action('after_setup_theme', array($WPLessPlugin, 'install'));
});

There's also a even more simple helper:

$WPLessPlugin = \WPLessPluginLoader::getInstance($callable);

will fetch an existing instance of the plugin or create one.


Those changes are tested in the listed use cases. Please let me know if I did oversee something. Any thoughts?

thom4parisot commented 7 years ago

What if the plugin is installed outside of composer, from the wp-plugins repository for instance?

mrgrain commented 7 years ago

Hi @oncletom, thanks for your question. Nothing will changes if used as a plugin. The new WPLessPluginLoader class will handle all the required file loading. It serves as a wrapper for WPPluginToolkitPlugin::create and mainly encapsulates the file path.

thom4parisot commented 7 years ago

OK i see your point!

I initially created WPPluginToolkitPlugin to share it across multiple plugin I would author. Sadly WordPress plugins SVN system does not allow submodules so it forced me to statically vendor this class.

So to be honest, if could totally be "de-abstracted" or worked out differently if that serves your proposal. Feel free to make the additional changes in a subsequent PR if needed :-)

Thanks again for your contribution!