CLI_Command::has_command
Detects if a command exists
This commands checks if a command is registered with WP-CLI. If the command is found then it returns with exit status 0. If the command doesn't exist, then it will exit with status 1.
OPTIONS
- <command_name>...
- The command
EXAMPLES
# The "site delete" command is registered. $ wp cli has-command "site delete" $ echo $? 0
# The "foo bar" command is not registered. $ wp cli has-command "foo bar" $ echo $? 1
# Install a WP-CLI package if not already installed $ if ! $(wp cli has-command doctor); then wp package install wp-cli/doctor-command; fi Installing package wp-cli/doctor-command (dev-main || dev-master || dev-trunk) Updating /home/person/.wp-cli/packages/composer.json to require the package... Using Composer to install the package... --- Success: Package installed.
Метод класса: CLI_Command{}
Хуков нет.
Возвращает
null. Ничего (null).
Использование
$CLI_Command = new CLI_Command(); $CLI_Command->has_command( $_, $assoc_args );
- $_(обязательный)
- .
- $assoc_args(обязательный)
- .
Код CLI_Command::has_command() CLI Command::has command WP-CLI 2.13.0-alpha
public function has_command( $_, $assoc_args ) {
// If command is input as a string, then explode it into array.
$command = explode( ' ', implode( ' ', $_ ) );
WP_CLI::halt( is_array( WP_CLI::get_runner()->find_command_to_run( $command ) ) ? 0 : 1 );
}