assely / framework

Assely is a PHP framework which brings a little joy to the WordPress development. Develop structured, easily scalable and complex WordPress websites and web applications with true pleasure.
MIT License
56 stars 7 forks source link

Changing package type to 'wordpress-muplugin' #8

Open jedrzejchalubek opened 7 years ago

jedrzejchalubek commented 7 years ago

I'm considering changing package type in composer.json file to wordpress-muplugin. This will enforce Bedrock to install framework as "not to turn off". It has a lot of sense, as the assely created themes absolutely requires framework.

Do you have any thoughts about this?

marcwieland95 commented 7 years ago

Yes, the idea about moving assely framework into a mu-plugin is good and useful. But there's a technical limitation:

WordPress only looks for PHP files right inside the mu-plugins directory, and (unlike for normal plugins) not for files in subdirectories. You may want to create a proxy PHP loader file inside the mu-plugins directory - https://codex.wordpress.org/Must_Use_Plugins

Using a proxy file isn't a good solution, maybe also not possible with composer - I don't know for sure.

This is a useful discussion in the roots forum: https://discourse.roots.io/t/composer-mu-plugins/1326/2

Bedrock is using an autoloader for mu-plugins, maybe this could be used: https://roots.io/bedrock/docs/mu-plugins-autoloader/

marcwieland95 commented 7 years ago

Just checked the usage as a mu-plugin. With Bedrocks autoloader it seems to work without proxy file. The compatibility function inside the theme needs some adjustments this way. We can check if a constant is defined instead of the is_plugin_active function.

if (! defined('ASSELY_FRAMEWORK_DIR') ) {
   ...
}
jedrzejchalubek commented 7 years ago

Yeah, Bedrock take care of autoloading mu-plugins. However, I don't know how this would behave in other stacks (Wordplate etc). Maybe we should not care about it at all 😈

The is_plugin_active function doesn't work for mu-plugins, so as you mentioned, we need to rely on something else (constans are good proposition).

marcwieland95 commented 7 years ago

Haha. Maybe we can add a note in the documentation to add the Bedrock Autoloader file manually when using other stacks.