plugin icon indicating copy to clipboard operation
plugin copied to clipboard

Defining console commands

Open Jaspervv opened this issue 6 years ago • 3 comments

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.

Jaspervv avatar Feb 14 '19 15:02 Jaspervv

@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.

jlambe avatar Feb 15 '19 16:02 jlambe

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.

Jaspervv avatar Mar 12 '19 10:03 Jaspervv

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.

jlambe avatar Mar 12 '19 13:03 jlambe