title: "WP_CLI::warning()" post_status: publish comment_status: open taxonomy: category: - wp-cli-handbook post_tag: - Internal Api - References - Repos


WP_CLI::warning()

显示以“Warning: ”为前缀的警告信息。


用法

WP_CLI::warning( $message )
$message (string|WP_Error|Exception|Throwable) 要写入 STDERR 的消息。
@return (void)

说明

警告信息会写入 STDERR,或者在提供 --quiet 标志时被丢弃。

当脚本执行应被允许继续时,请使用此方法代替 WP_CLI::debug()

# `wp plugin activate` 在插件为网络激活时跳过激活。
$status = $this->get_status( $plugin->file );
// 网络激活是最高级别的激活状态
if ( 'active-network' === $status ) {
  WP_CLI::warning( "Plugin '{$plugin->name}' is already network active." );
  continue;
}

内部 API 文档在每次发布时从 WP-CLI 代码库生成。如需改进,请提交拉取请求。


相关