Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trigger new 'cli_init' hook during WordPress plugins_loaded action. #4861

Copy path View file
@@ -1666,3 +1666,21 @@ Feature: WP-CLI Commands
"""
core custom-subcommand
"""

Scenario: An activated plugin should successfully add custom commands when hooked on the cli_init action
Given a WP installation
And a wp-content/plugins/custom-command/custom-cmd.php file:
"""
<?php
// Plugin Name: Custom Command
add_action( 'cli_init', function() {
WP_CLI::add_command( 'custom', function () {} );
} );
"""
And I run `wp plugin activate custom-command`
When I run `wp custom --help`
Then STDOUT should contain:
"""
wp custom
"""

This comment has been minimized.

Copy link
@schlessera

schlessera Jul 20, 2018

Member

CS: Missing new line.

Copy path View file
@@ -966,7 +966,6 @@ private function set_alias( $alias ) {
}
public function start() {
// Enable PHP error reporting to stderr if testing. Will need to be re-enabled after WP loads.
if ( getenv( 'BEHAT_RUN' ) ) {
$this->enable_error_reporting();
@@ -1487,6 +1486,10 @@ function( $url, $path, $scheme, $blog_id ) {
4
);
// Set up hook for WP-CLI packages to use.

This comment has been minimized.

Copy link
@schlessera

schlessera Jul 20, 2018

Member

This is misleading, WP-CLI packages don't need this.
It should be something like:

// Set up hook for plugins & themes to conditionally add WP-CLI commands.
WP_CLI::add_wp_hook( 'init', function () {
do_action( 'cli_init' );
} );
}
/**
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.