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 );

Method of the class: WP_CLI{}

No Hooks.

Return

null. Nothing (null).

Usage

$result = WP_CLI::confirm( $question, $assoc_args );
$question(string) (required)
Question to display before the prompt.
$assoc_args(array)
Skips prompt if 'yes' is provided.
Default: []

WP_CLI::confirm() code 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;
		}
	}
}