diff --git a/features/runner.feature b/features/runner.feature index 9f1c2b7d52..c39c898d6a 100644 --- a/features/runner.feature +++ b/features/runner.feature @@ -79,3 +79,23 @@ Feature: Runner WP-CLI Did you mean 'meta'? """ And the return code should be 1 + + Scenario: Suggest 'wp term ' when an invalid taxonomy command is run + Given a WP install + + When I try `wp category list` + Then STDERR should contain: + """ + Did you mean 'wp term '? + """ + And the return code should be 1 + +Scenario: Suggest 'wp post ' when an invalid post type command is run + Given a WP install + + When I try `wp page create` + Then STDERR should contain: + """ + Did you mean 'wp post --post_type=page '? + """ + And the return code should be 1 diff --git a/php/WP_CLI/Runner.php b/php/WP_CLI/Runner.php index 6254fd64df..c56af4e592 100644 --- a/php/WP_CLI/Runner.php +++ b/php/WP_CLI/Runner.php @@ -396,6 +396,16 @@ public function find_command_to_run( $args ) { $suggestion = $this->get_subcommand_suggestion( $full_name, $command ); + // If the functions are available, it means WordPress is available + // and has already been loaded. + if ( function_exists( '\taxonomy_exists' ) ) { + if ( \taxonomy_exists( $cmd_path[0] ) ) { + $suggestion = 'wp term '; + } elseif ( \post_type_exists( $cmd_path[0] ) ) { + $suggestion = "wp post --post_type={$cmd_path[0]} "; + } + } + return sprintf( "'%s' is not a registered wp command. See 'wp help' for available commands.%s", $full_name,