本文整理汇总了PHP中WP_CLI::colorize方法的典型用法代码示例。如果您正苦于以下问题:PHP WP_CLI::colorize方法的具体用法?PHP WP_CLI::colorize怎么用?PHP WP_CLI::colorize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WP_CLI
的用法示例。
在下文中一共展示了WP_CLI::colorize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: migrate
/**
* Migrate meta values to taxonomy terms. Delete meta after import
*
* ## OPTIONS
*
* <meta-key>
* : Meta key to convert
*
* <taxonomy-slug>
* : Taxonomy to move values into
*
* [--<field>=<value>]
* : One or more args to pass to WP_Query.
*
* ## EXAMPLES
*
* wp mtt migrate meta_key taxonomy_slug
* wp mtt migrate meta_key taxonomy_slug --posts_per_page=200 --paged=2
*
*/
function migrate($args, $assoc_args)
{
list($meta_key, $taxonomy) = $args;
if (!($taxonomy_object = get_taxonomy($taxonomy))) {
WP_CLI::error(sprintf("The taxonomy '%s' doesn't exist", $taxonomy));
}
$defaults = array('post_type' => $taxonomy_object->object_type, 'posts_per_page' => -1, 'post_status' => 'any');
$query_args = array_merge($defaults, $assoc_args);
$query = new WP_Query($query_args);
// summary
WP_CLI::log(sprintf("---\nPer page: %d \nPage: %d \nTotal pages: %d\n---", $query_args['posts_per_page'], isset($query_args['paged']) ? $query_args['paged'] : 1, $query->max_num_pages));
while ($query->have_posts()) {
$query->the_post();
$id = get_the_id();
// get meta
$metas = get_post_meta($id, $meta_key);
// create term
if (!$metas) {
WP_CLI::log(WP_CLI::colorize("%c[{$id}]%n No meta, skipped"));
} else {
if (!is_wp_error(wp_set_object_terms($id, $metas, $taxonomy, true))) {
WP_CLI::log(WP_CLI::colorize("%g[{$id}]%n Migrated: " . implode(', ', $metas)));
// clean meta
delete_post_meta($id, $meta_key);
} else {
WP_CLI::log(WP_CLI::colorize("%r[{$id}]%n Error: Could not set terms for post"));
}
}
}
}
示例2: show_legend
private function show_legend($items)
{
$statuses = array_unique(wp_list_pluck($items, 'status'));
$legend_line = array();
foreach ($statuses as $status) {
$legend_line[] = sprintf('%s%s = %s%%n', $this->get_color($status), $this->map['short'][$status], $this->map['long'][$status]);
}
if (in_array(true, wp_list_pluck($items, 'update'))) {
$legend_line[] = '%yU = Update Available%n';
}
\WP_CLI::line('Legend: ' . \WP_CLI::colorize(implode(', ', $legend_line)));
}
示例3: show_help
private static function show_help($command)
{
$out = self::get_initial_markdown($command);
$longdesc = $command->get_longdesc();
if ($longdesc) {
$out .= wordwrap($longdesc, 79) . "\n";
}
// section headers
$out = preg_replace('/^## ([A-Z ]+)/m', WP_CLI::colorize('%9\\1%n'), $out);
// definition lists
$out = preg_replace_callback('/([^\\n]+)\\n: (.+?)(\\n\\n|$)/s', array(__CLASS__, 'rewrap_param_desc'), $out);
$out = str_replace("\t", ' ', $out);
self::pass_through_pager($out);
}
示例4: check
/**
* Prints a greeting.
*
* ## OPTIONS
*
* <name>
* : The name of the person to greet.
*
* ## EXAMPLES
*
* wp theme-check check twentyfifteen
*
* @synopsis <name> [--disable-themeforest]
*/
function check($args, $assoc_args)
{
global $checkcount, $themechecks;
$theme = $this->fetcher->get_check($args[0]);
$files = $theme->get_files(null, -1);
$css = $php = $other = array();
if ($files) {
foreach ($files as $key => $filename) {
if (substr($filename, -4) == '.php') {
$php[$filename] = php_strip_whitespace($filename);
} else {
if (substr($filename, -4) == '.css') {
$css[$filename] = file_get_contents($filename);
} else {
$other[$filename] = !is_dir($filename) ? file_get_contents($filename) : '';
}
}
}
// run the checks
$success = run_themechecks($php, $css, $other);
foreach ($themechecks as $check) {
if ($check instanceof themecheck) {
$errors = $check->getError();
if (!empty($error)) {
$errors = array_merge($error, $errors);
}
$errors = array_map('strip_tags', $errors);
foreach ($errors as $key => $value) {
list($type, $message) = explode(':', $value, 2);
switch (trim($type)) {
case 'WARNING':
WP_CLI::line(WP_CLI::colorize('%rWARNING:%n ' . trim($message)));
break;
case 'INFO':
WP_CLI::line(WP_CLI::colorize('%bINFO:%n ' . trim($message)));
break;
case 'RECOMMENDED':
WP_CLI::line(WP_CLI::colorize('%gRECOMMENDED:%n ' . trim($message)));
break;
case 'REQUIRED':
WP_CLI::line(WP_CLI::colorize('%rREQUIRED:%n ' . trim($message)));
break;
}
}
}
}
}
}
示例5: status
/**
* Show the Redis object cache status and (when possible) client.
*
* ## EXAMPLES
*
* wp redis status
*
*/
public function status()
{
$plugin = $GLOBALS['redisObjectCache'];
$status = $plugin->get_status();
$client = $plugin->get_redis_client_name();
switch ($status) {
case __('Disabled', 'redis-cache'):
$status = WP_CLI::colorize("%y{$status}%n");
break;
case __('Connected', 'redis-cache'):
$status = WP_CLI::colorize("%g{$status}%n");
break;
case __('Not Connected', 'redis-cache'):
$status = WP_CLI::colorize("%r{$status}%n");
break;
}
WP_CLI::line('Status: ' . $status);
if (!is_null($client)) {
WP_CLI::line('Client: ' . $client);
}
}
示例6: index
/**
* Index all posts for a site or network wide
*
* @synopsis [--setup] [--network-wide] [--posts-per-page] [--no-bulk] [--offset] [--show-bulk-errors]
* @param array $args
*
* @since 0.1.2
*
* @param array $assoc_args
*/
public function index($args, $assoc_args)
{
$this->_connect_check();
if (!empty($assoc_args['posts-per-page'])) {
$assoc_args['posts-per-page'] = absint($assoc_args['posts-per-page']);
} else {
$assoc_args['posts-per-page'] = 350;
}
if (!empty($assoc_args['offset'])) {
$assoc_args['offset'] = absint($assoc_args['offset']);
} else {
$assoc_args['offset'] = 0;
}
$total_indexed = 0;
/**
* Prior to the index command invoking
* Useful for deregistering filters/actions that occur during a query request
*
* @since 1.4.1
*/
do_action('ep_wp_cli_pre_index', $args, $assoc_args);
// Deactivate our search integration
$this->deactivate();
timer_start();
// Run setup if flag was passed
if (isset($assoc_args['setup']) && true === $assoc_args['setup']) {
// Right now setup is just the put_mapping command, as this also deletes the index(s) first
$this->put_mapping($args, $assoc_args);
}
if (isset($assoc_args['network-wide']) && is_multisite()) {
if (!is_numeric($assoc_args['network-wide'])) {
$assoc_args['network-wide'] = 0;
}
WP_CLI::log(__('Indexing posts network-wide...', 'elasticpress'));
$sites = ep_get_sites($assoc_args['network-wide']);
foreach ($sites as $site) {
switch_to_blog($site['blog_id']);
$result = $this->_index_helper(isset($assoc_args['no-bulk']), $assoc_args['posts-per-page'], $assoc_args['offset'], isset($assoc_args['show-bulk-errors']));
$total_indexed += $result['synced'];
WP_CLI::log(sprintf(__('Number of posts synced on site %d: %d', 'elasticpress'), $site['blog_id'], $result['synced']));
if (!empty($result['errors'])) {
WP_CLI::error(sprintf(__('Number of post sync errors on site %d: %d', 'elasticpress'), $site['blog_id'], count($result['errors'])));
}
restore_current_blog();
}
WP_CLI::log(__('Recreating network alias...', 'elasticpress'));
$this->_create_network_alias();
WP_CLI::log(sprintf(__('Total number of posts indexed: %d', 'elasticpress'), $total_indexed));
} else {
WP_CLI::log(__('Indexing posts...', 'elasticpress'));
$result = $this->_index_helper(isset($assoc_args['no-bulk']), $assoc_args['posts-per-page'], $assoc_args['offset'], isset($assoc_args['show-bulk-errors']));
WP_CLI::log(sprintf(__('Number of posts synced on site %d: %d', 'elasticpress'), get_current_blog_id(), $result['synced']));
if (!empty($result['errors'])) {
WP_CLI::error(sprintf(__('Number of post sync errors on site %d: %d', 'elasticpress'), get_current_blog_id(), count($result['errors'])));
}
}
WP_CLI::log(WP_CLI::colorize('%Y' . __('Total time elapsed: ', 'elasticpress') . '%N' . timer_stop()));
// Reactivate our search integration
$this->activate();
WP_CLI::success(__('Done!', 'elasticpress'));
}
示例7: discounts
/**
* Get discount details for on your EDD site
*
* ## OPTIONS
*
* --id=<discount_id>: A specific discount ID to retrieve
*
* ## EXAMPLES
*
* wp edd discounts --id=103
*/
public function discounts($args, $assoc_args)
{
$discount_id = isset($assoc_args) && array_key_exists('id', $assoc_args) ? absint($assoc_args['id']) : false;
$discounts = $this->api->get_discounts($discount_id);
if (isset($discounts['error'])) {
WP_CLI::error($discounts['error']);
}
if (empty($discounts)) {
WP_CLI::error(__('No discounts found', 'easy-digital-downloads'));
return;
}
foreach ($discounts['discounts'] as $discount) {
WP_CLI::line(WP_CLI::colorize('%G' . $discount['ID'] . '%N'));
WP_CLI::line(sprintf(__('Name: %s', 'easy-digital-downloads'), $discount['name']));
WP_CLI::line(sprintf(__('Code: %s', 'easy-digital-downloads'), $discount['code']));
if ($discount['type'] == 'percent') {
$amount = $discount['amount'] . '%';
} else {
$amount = edd_format_amount($discount['amount']) . ' ' . edd_get_currency();
}
WP_CLI::line(sprintf(__('Amount: %s', 'easy-digital-downloads'), $amount));
WP_CLI::line(sprintf(__('Uses: %s', 'easy-digital-downloads'), $discount['uses']));
WP_CLI::line(sprintf(__('Max Uses: %s', 'easy-digital-downloads'), $discount['max_uses'] == '0' ? __('Unlimited', 'easy-digital-downloads') : $discount['max_uses']));
WP_CLI::line(sprintf(__('Start Date: %s', 'easy-digital-downloads'), empty($discount['start_date']) ? __('No Start Date', 'easy-digital-downloads') : $discount['start_date']));
WP_CLI::line(sprintf(__('Expiration Date: %s', 'easy-digital-downloads'), empty($discount['exp_date']) ? __('No Expiration', 'easy-digital-downloads') : $discount['exp_date']));
WP_CLI::line(sprintf(__('Status: %s', 'easy-digital-downloads'), ucwords($discount['status'])));
WP_CLI::line('');
if (array_key_exists(0, $discount['product_requirements'])) {
WP_CLI::line(__('Product Requirements:', 'easy-digital-downloads'));
foreach ($discount['product_requirements'] as $req => $req_id) {
WP_CLI::line(sprintf(__(' Product: %s', 'easy-digital-downloads'), $req_id));
}
}
WP_CLI::line('');
WP_CLI::line(sprintf(__('Global Discount: %s', 'easy-digital-downloads'), empty($discount['global_discount']) ? 'False' : 'True'));
WP_CLI::line(sprintf(__('Single Use: %s', 'easy-digital-downloads'), empty($discount['single_use']) ? 'False' : 'True'));
WP_CLI::line('');
}
}
示例8: status_single
protected function status_single($args)
{
$plugin = $this->fetcher->get_check($args[0]);
$file = $plugin->file;
$details = $this->get_details($file);
$status = $this->format_status($this->get_status($file), 'long');
$version = $details['Version'];
if ($this->has_update($file)) {
$version .= ' (%gUpdate available%n)';
}
echo WP_CLI::colorize(\WP_CLI\Utils\mustache_render('plugin-status.mustache', array('slug' => Utils\get_plugin_name($file), 'status' => $status, 'version' => $version, 'name' => $details['Name'], 'author' => $details['Author'], 'description' => $details['Description'])));
}
示例9: bar
/**
* Create a bar that spans with width of the console
*
* ## OPTIONS
*
* [<character>]
* : The character(s) to make the bar with. Default =
*
* [--c=<c>]
* : Color for bar. Default %p
*
*
* ## EXAMPLES
*
* wp <command> bar
*
* wp <command> bar '-~' --c='%r'
*
* wp <command> bar '+-' --c='%r%3'
*/
function bar($args = array(), $assoc_args = array())
{
$char = isset($args[0]) ? $args[0] : '=';
$cols = \cli\Shell::columns();
$line = substr(str_repeat($char, $cols), 0, $cols);
if (!isset($assoc_args['c'])) {
$color = '%p';
// https://github.com/jlogsdon/php-cli-tools/blob/master/lib/cli/Colors.php#L113
} else {
$color = $assoc_args['c'];
$color = '%' . trim($color, '%');
}
WP_CLI::line(WP_CLI::colorize($color . $line . '%n'));
}
示例10: error
/**
* Write an error message to STDERR, prefixed with "Error: ".
*
* @param string $message Message to write.
*/
public function error($message)
{
fwrite(STDERR, \WP_CLI::colorize("%RError:%n {$message}\n"));
}
示例11: handle_prefix_mismatch
/**
*
* Detects a database prefix mismatch and displays a CLI message about it. Does not interrupt the migration.
*
* @param $post_data
*
* @return bool
*/
public function handle_prefix_mismatch($post_data, $profile)
{
global $wpdb;
$local_prefix = $wpdb->base_prefix;
$remote_prefix = $this->get_remote_prefix($post_data);
$mismatch = null;
$message = '';
if (!empty($local_prefix) && !empty($remote_prefix)) {
$mismatch = false;
if ($local_prefix !== $remote_prefix) {
$mismatch = true;
}
}
$subsite_prefix_mismatch = $this->is_multisite_prefix_mismatch($post_data, $profile, $mismatch);
if (true === $mismatch) {
if (isset($post_data['intent'])) {
$message = "%Y" . __("Database table prefix differs between installations.", 'wp-migrate-db-cli');
$message .= "%n \n%R";
if (true === $subsite_prefix_mismatch) {
$message .= sprintf(__("We have detected you have table prefix \"%s\" at %s but have \"%s\" here. Multisite Tools currently only supports migrating subsites between sites with the same base table prefix.", 'wp-migrate-db-cli'), $remote_prefix, $post_data['site_details']['remote']['site_url'], $wpdb->base_prefix);
} else {
if ('push' == $post_data['intent']) {
$message .= sprintf(__("The remote database uses a prefix of \"%s\". This migration will create new tables in the remote database with a prefix of \"%s\". \nTo use these new tables, AFTER the migration is complete, you will need to edit the wp-config.php file on the remote server and change the \$table_prefix variable to \"%s\"", 'wp-migrate-db-cli'), $remote_prefix, $wpdb->base_prefix, $wpdb->base_prefix);
} else {
if ('pull' == $post_data['intent']) {
$message .= sprintf(__("The local database uses a prefix of \"%s\". This migration will create new tables in the local database with a prefix of \"%s\". \nTo use these new tables, AFTER the migration is complete, you will need to edit your wp-config.php file in your local environment and change the \$table_prefix variable to \"%s\"", 'wp-migrate-db-cli'), $wpdb->base_prefix, $remote_prefix, $remote_prefix);
}
}
}
$message .= "%n";
}
// Only display the CLI warning if invoked manually.
if (!defined('DOING_WPMDB_TESTS')) {
if (false === $subsite_prefix_mismatch) {
WP_CLI::warning(WP_CLI::colorize($message));
} else {
WP_CLI::error(WP_CLI::colorize($message));
}
}
}
return $mismatch;
}
示例12: blame
//.........这里部分代码省略.........
try {
if (2 === count($func)) {
$ref = new ReflectionMethod($func[0], $func[1]);
} else {
$ref = new ReflectionFunction($func[0]);
}
$filename = $ref->getFileName();
} catch (ReflectionException $e) {
// @TODO message about using the --filename arg
WP_CLI::error($e->getMessage());
}
} else {
if ($assoc_args['filename']) {
if (file_exists($assoc_args['filename'])) {
$filename = $assoc_args['filename'];
} elseif (file_exists(ABSPATH . $assoc_args['filename'])) {
$filename = ABSPATH . $assoc_args['filename'];
} else {
WP_CLI::error(sprintf("File '%s' does not exist", $assoc_args['filename']));
}
}
}
if ($revision) {
$cmd = Utils\esc_cmd('svn blame %s@%s', $filename, $revision);
WP_CLI::line(sprintf('Fetching r%d...', $revision));
WP_CLI::line('This can be *very* slow for large files');
} else {
$cmd = Utils\esc_cmd('svn blame %s', $filename);
}
$text = self::launch_command($cmd);
if (is_wp_error($text)) {
WP_CLI::error($text);
}
$text = str_replace(array("\r\n", "\r"), "\n", $text);
$data = explode("\n", "\n" . $text);
$lazy_explode = explode(sprintf('function %s', $function_name), $text, 2);
$start_line = substr_count($lazy_explode[0], "\n") + 1;
$func_onwards = explode("\n", $lazy_explode[1]);
$func_length = 0;
foreach ($func_onwards as $k => $v) {
if (18 === strpos($v, '}')) {
$func_length = $k;
break;
}
}
if (empty($func_length)) {
WP_CLI::error('¯\\_(ツ)_/¯');
}
$do_docblock = $assoc_args['docblock'] && ' */' === substr($data[$start_line - 1], 18, 3);
if ($do_docblock) {
while ('/**' !== substr($data[$start_line], 18, 3)) {
$start_line--;
$func_length++;
}
}
$data = $raw_data = array_slice($data, $start_line, $func_length + 1, true);
$revisions = array();
$data = array_map(function ($line, $value) use(&$revisions) {
if (preg_match('|^[ ]*([0-9]+)|', $value, $matches)) {
$revisions[$line] = intval($matches[1]);
}
return $value;
}, array_keys($data), $data);
$revision_list = array_unique($revisions);
rsort($revision_list);
$latest = $revision_list[0];
$out = array_map(function ($line, $value) use($revision_list) {
$n = str_pad($line, 4, ' ', STR_PAD_LEFT);
$return = "{$n} | {$value}";
if (preg_match('|^[ ]*([0-9]+)|', $value, $matches)) {
if ($matches[1] == $revision_list[0]) {
$return = WP_CLI::colorize('%K' . $return . '%n');
}
}
return $return;
}, array_keys($raw_data), $data);
WP_CLI::line(str_repeat('-', 100));
if ($revision) {
WP_CLI::line(sprintf('%s() at r%s', $function_name, $revision));
} else {
WP_CLI::line(sprintf('%s() in your working copy', $function_name));
}
WP_CLI::line(str_repeat('-', 100));
WP_CLI::line('');
WP_CLI::line(implode("\n", $out));
WP_CLI::line('');
WP_CLI::line(str_repeat('-', 100));
$revision = $revision_list[1];
break;
}
WP_CLI::line('');
WP_CLI::line(sprintf('[v] View changeset in your browser (r%d)', $latest));
WP_CLI::line(sprintf('[b] Back in history (r%d)', $revision));
WP_CLI::line('[g] Go directly to a specified revision');
WP_CLI::line('[q] Quit');
WP_CLI::line('');
$prompt = strtolower($this->prompt('What next?', '?'));
}
WP_CLI::success('DONE');
}
示例13: index
/**
* Index all posts for a site or network wide
*
* @synopsis [--setup] [--network-wide] [--posts-per-page] [--no-bulk]
* @param array $args
*
* @since 0.1.2
*
* @param array $assoc_args
*/
public function index($args, $assoc_args)
{
$this->_connect_check();
if (!empty($assoc_args['posts-per-page'])) {
$assoc_args['posts-per-page'] = absint($assoc_args['posts-per-page']);
} else {
$assoc_args['posts-per-page'] = 350;
}
$total_indexed = 0;
// Deactivate our search integration
$this->deactivate();
timer_start();
// Run setup if flag was passed
if (isset($assoc_args['setup']) && true === $assoc_args['setup']) {
// Right now setup is just the put_mapping command, as this also deletes the index(s) first
$this->put_mapping($args, $assoc_args);
}
if (!empty($assoc_args['network-wide']) && is_multisite()) {
\WP_CLI::log(__('Indexing posts network-wide...', 'elasticpress'));
$sites = ep_get_sites();
foreach ($sites as $site) {
switch_to_blog($site['blog_id']);
$result = $this->_index_helper(isset($assoc_args['no-bulk']), $assoc_args['posts-per-page']);
$total_indexed += $result['synced'];
\WP_CLI::log(sprintf(__('Number of posts synced on site %d: %d', 'elasticpress'), $site['blog_id'], $result['synced']));
if (!empty($result['errors'])) {
\WP_CLI::error(sprintf(__('Number of post sync errors on site %d: %d', 'elasticpress'), $site['blog_id'], count($result['errors'])));
}
restore_current_blog();
}
\WP_CLI::log(__('Recreating network alias...', 'elasticpress'));
$this->_create_network_alias();
\WP_CLI::log(sprintf(__('Total number of posts indexed: %d', 'elasticpress'), $total_indexed));
} else {
\WP_CLI::log(__('Indexing posts...', 'elasticpress'));
$result = $this->_index_helper(isset($assoc_args['no-bulk']), $assoc_args['posts-per-page']);
\WP_CLI::log(sprintf(__('Number of posts synced on site %d: %d', 'elasticpress'), get_current_blog_id(), $result['synced']));
if (!empty($result['errors'])) {
\WP_CLI::error(sprintf(__('Number of post sync errors on site %d: %d', 'elasticpress'), get_current_blog_id(), count($result['errors'])));
}
}
\WP_CLI::log(\WP_CLI::colorize('%Y' . __('Total time elapsed: ', 'elasticpress') . '%N' . timer_stop()));
// Reactivate our search integration
$this->activate();
\WP_CLI::success(__('Done!', 'elasticpress'));
}
示例14: log
/**
* Allows us to log if we are using WP_CLI to fire this cron task
*
* @see http://wp-cli.org/docs/internal-api/#output
*
* @param string $type What kind of log is this
* @param string $message message displayed
*
* @return void
*/
public function log($type = 'colorize', $message = '')
{
// Log on our Structure
Tribe__Main::instance()->log()->log_debug($message, 'aggregator');
// Only go further if we have WP_CLI
if (!class_exists('WP_CLI')) {
return false;
}
switch ($type) {
case 'error':
WP_CLI::error($message);
break;
case 'warning':
WP_CLI::warning($message);
break;
case 'success':
WP_CLI::success($message);
break;
case 'debug':
WP_CLI::debug($message, 'aggregator');
break;
case 'colorize':
default:
WP_CLI::log(WP_CLI::colorize($message));
break;
}
}
示例15: bar
/**
* Create a bar that spans with width of the console
*
* @param array $args Only expects a zero-indexed value, the character to build the bar with
* @param array $assoc_args
* string 'c' Color value. Default %p
* integer 'w' Width percentage, 0-100. Default 100
* string 'text' Message to show in bar
*/
private function bar($args = array(), $assoc_args = array())
{
$char = isset($args[0]) ? $args[0] : '=';
$cols = \cli\Shell::columns();
if (isset($assoc_args['w'])) {
$cols = floor($cols * ($assoc_args['w'] / 100));
}
$line = substr(str_repeat($char, $cols), 0, $cols);
if (isset($assoc_args['text'])) {
$text = "{$char}{$char}{$char} {$assoc_args['text']} ";
$len = strlen($text);
$line = $text . substr($line, $len);
}
if (!isset($assoc_args['c'])) {
$color = '%p';
// https://github.com/jlogsdon/php-cli-tools/blob/master/lib/cli/Colors.php#L113
} else {
$color = $assoc_args['c'];
$color = '%' . trim($color, '%');
}
WP_CLI::log(WP_CLI::colorize($color . $line . '%n'));
}