Add name context to before_invoke and after_invoke by coccoinomane · Pull Request #5712 · wp-cli/wp-cli
Ciao @danielbachhuber, and thank you for your reply!
I had a command structured in this way:
<?php class TestHook { public function __invoke( $args ) { WP_CLI::line( "In command" ); } } WP_CLI::add_command( 'test hook', // two words 'TestHook', [ 'before_invoke' => function() { WP_CLI::line( "In before_invoke" ); }, 'after_invoke' => function() { WP_CLI::line( "In after_invoke" ); } ] );
When I invoked the command, I was suprised getting the following output:
$ wp test my hook
In before_invoke
In before_invoke
In command
In after_invoke
In after_invoke
Please note that by changing the command's name to a single word (e.g. testhook instead of test hook), it works fine.
The problem originates here. The easiest fix would be to just remove the WP_CLI::do_hook( "before_invoke:{$parent}" ); line, but I am not sure what the side effects would be.