WP_CLI::warning PHP Method

warning() public static method

Warning message is written to STDERR. Use instead of WP_CLI::debug() when script execution should be permitted to continue. # wp plugin activate skips activation when plugin is network active. $status = $this->get_status( $plugin->file ); Network-active is the highest level of activation status if ( 'active-network' === $status ) { WP_CLI::warning( "Plugin '{$plugin->name}' is already network active." ); continue; }
public static warning ( string $message ) : null
$message string Message to write to STDERR.
return null
    public static function warning($message)
    {
        self::$logger->warning(self::error_to_string($message));
    }

Usage Example

 /**
  * Checks one or more comments against the Akismet API.
  *
  * ## OPTIONS
  * <comment_id>...
  * : The ID(s) of the comment(s) to check.
  *
  * [--noaction]
  * : Don't change the status of the comment. Just report what Akismet thinks it is.
  *
  * ## EXAMPLES
  *
  *     wp akismet check 12345
  *
  * @alias comment-check
  */
 public function check($args, $assoc_args)
 {
     foreach ($args as $comment_id) {
         if (isset($assoc_args['noaction'])) {
             // Check the comment, but don't reclassify it.
             $api_response = Akismet::check_db_comment($comment_id, 'wp-cli');
         } else {
             $api_response = Akismet::recheck_comment($comment_id, 'wp-cli');
         }
         if ('true' === $api_response) {
             WP_CLI::line(sprintf(__("Comment #%d is spam.", 'akismet'), $comment_id));
         } else {
             if ('false' === $api_response) {
                 WP_CLI::line(sprintf(__("Comment #%d is not spam.", 'akismet'), $comment_id));
             } else {
                 if (false === $api_response) {
                     WP_CLI::error(__("Failed to connect to Akismet.", 'akismet'));
                 } else {
                     if (is_wp_error($api_response)) {
                         WP_CLI::warning(sprintf(__("Comment #%d could not be checked.", 'akismet'), $comment_id));
                     }
                 }
             }
         }
     }
 }
All Usage Examples Of WP_CLI::warning