themosis / plugin

Themosis framework plugin boilerplate.
54 stars 19 forks source link

Defining console commands #18

Open Jaspervv opened 5 years ago

Jaspervv commented 5 years ago

Is it possible to define console commands from within a plugin? And if so.. how?

The only way made this possible was by editing the themosis/themosis's App\Console\Kernel. But I would like the plugin to work independently.

jlambe commented 5 years ago

@Jaspervv Normally you should have access to the Command alias which lets you call commands defined from the root application.

Now for defining commands, I haven't extended the plugin manager for this but this can actually be a great feature addition. So yes, for now I think you can't define commands from the plugin.

Jaspervv commented 5 years ago

Thanks, I checked and calling commands can be done with

Console::call('key:generate');

For anyone coming across this in the future, be sure to check Laravel's Documentation.


Implementing commands support for plugins requires more than I thought, php console never initialises WordPress, therefor plugins and the PluginLoader are never initialised either.

jlambe commented 5 years ago

The idea with plugin commands would be to be able to register commands within the application without having to load WordPress. WordPress will always try to look after a database and for running commands, it is not necessary.