WP_CLI::confirm()public staticWP-CLI 1.0

Ask for confirmation before running a destructive operation.

If 'y' is provided to the question, the script execution continues. If 'n' or any other response is provided to the question, script exits.

# `wp db drop` asks for confirmation before dropping the database.

WP_CLI::confirm( "Are you sure you want to drop the database?", $assoc_args );

Метод класса: WP_CLI{}

Хуков нет.

Возвращает

null. Ничего (null).

Использование

$result = WP_CLI::confirm( $question, $assoc_args );
$question(строка) (обязательный)
Question to display before the prompt.
$assoc_args(массив)
Skips prompt if 'yes' is provided.
По умолчанию: []

Код WP_CLI::confirm() WP-CLI 2.8.0-alpha

public static function confirm( $question, $assoc_args = [] ) {
	if ( ! Utils\get_flag_value( $assoc_args, 'yes' ) ) {
		fwrite( STDOUT, $question . ' [y/n] ' );

		$answer = strtolower( trim( fgets( STDIN ) ) );

		if ( 'y' !== $answer ) {
			exit;
		}
	}
}