How can I run a wp cli command when a wordpress hook is called on my website.
On user registration hook, I would like to run a wp cli command to activate a license.
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It only takes a minute to sign up.Sign up to join this community
Depends on what you want to do. If you want to run the PHP code that's behind the WP-CLI code you might consider looking at https://github.com/wp-cli/entity-command
Maybe you don't actually need WP-CLI but the corresponding code behind it. Most WP-CLI commands have Wordpress equivalents. For example of what I was trying to do today, the
wp menu create "My Menu" command is defined here:
https://github.com/wp-cli/entity-command/blob/master/src/Menu_Command.php. (It was much easier to find documentation for WP-CLI for this because 99% of results for Wordpress describe how to do it via the admin panel.)
Basically it just uses the WP function:
65: $menu_id = wp_create_nav_menu( $args );
> wp menu create "My Menu" on the commandline is roughly equivalent to
wp_create_nav_menu('My Menu') in a
Similarly, the plugin command would be addressed as a WP-CLI extension command defined in Plugin_Command.php which uses the Wordpress command activate_plugin(). If you want to know the WP version of the WP-CLI command you could look it up yourself or include the specific command you want to know in your question.
You can use the PHP exec() function to run wp-cli commands.
<?php exec('wp core download'); ?>
Use with care. Further reading: