WP_CLI::success PHP Method

success() public static method

Success message is written to STDOUT. Typically recommended to inform user of successful script conclusion. # wp rewrite flush expects 'rewrite_rules' option to be set after flush. flush_rewrite_rules( \WP_CLI\Utils\get_flag_value( $assoc_args, 'hard' ) ); if ( ! get_option( 'rewrite_rules' ) ) { WP_CLI::warning( "Rewrite rules are empty." ); } else { WP_CLI::success( 'Rewrite rules flushed.' ); }
public static success ( string $message ) : null
$message string Message to write to STDOUT.
return null
    public static function success($message)
    {
        self::$logger->success($message);
    }

Usage Example

Example #1
1
 /**
  * Clear something from the cache
  *
  * @param array $args
  * @param array $vars
  */
 function flush($args = array(), $vars = array())
 {
     if (function_exists('w3tc_pgcache_flush')) {
         $args = array_unique($args);
         do {
             $cache_type = array_shift($args);
             switch ($cache_type) {
                 case 'db':
                 case 'database':
                     if (w3tc_dbcache_flush()) {
                         WP_CLI::success('The object cache is flushed successfully.');
                     } else {
                         WP_CLI::error('Flushing the object cache failed.');
                     }
                     break;
                 case 'minify':
                     if (w3tc_minify_flush()) {
                         WP_CLI::success('The object cache is flushed successfully.');
                     } else {
                         WP_CLI::error('Flushing the object cache failed.');
                     }
                     break;
                 case 'object':
                     if (w3tc_objectcache_flush()) {
                         WP_CLI::success('The object cache is flushed successfully.');
                     } else {
                         WP_CLI::error('Flushing the object cache failed.');
                     }
                     break;
                 case 'post':
                 default:
                     if (isset($vars['post_id'])) {
                         if (is_numeric($vars['post_id'])) {
                             w3tc_pgcache_flush_post($vars['post_id']);
                         } else {
                             WP_CLI::error('This is not a valid post id.');
                         }
                         w3tc_pgcache_flush_post($vars['post_id']);
                     } elseif (isset($vars['permalink'])) {
                         $id = url_to_postid($vars['permalink']);
                         if (is_numeric($id)) {
                             w3tc_pgcache_flush_post($id);
                         } else {
                             WP_CLI::error('There is no post with this permalink.');
                         }
                     } else {
                         if (isset($flushed_page_cache) && $flushed_page_cache) {
                             break;
                         }
                         $flushed_page_cache = true;
                         w3tc_pgcache_flush();
                     }
             }
         } while (!empty($args));
     } else {
         WP_CLI::error('The W3 Total Cache could not be found, is it installed?');
     }
 }
All Usage Examples Of WP_CLI::success