本文整理汇总了PHP中WP_CLI::out方法的典型用法代码示例。如果您正苦于以下问题:PHP WP_CLI::out方法的具体用法?PHP WP_CLI::out怎么用?PHP WP_CLI::out使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WP_CLI
的用法示例。
在下文中一共展示了WP_CLI::out方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _list
/**
* Get a list of posts.
*
* @subcommand list
* @synopsis [--<field>=<value>] [--ids]
*/
public function _list($_, $assoc_args)
{
$query_args = array('posts_per_page' => -1);
foreach ($assoc_args as $key => $value) {
if (true === $value) {
continue;
}
$query_args[$key] = $value;
}
if (isset($assoc_args['ids'])) {
$query_args['fields'] = 'ids';
}
$query = new WP_Query($query_args);
if (isset($assoc_args['ids'])) {
WP_CLI::out(implode(' ', $query->posts));
} else {
$fields = array('ID', 'post_title', 'post_name', 'post_date');
$table = new \cli\Table();
$table->setHeaders($fields);
foreach ($query->posts as $post) {
$line = array();
foreach ($fields as $field) {
$line[] = $post->{$field};
}
$table->addRow($line);
}
$table->display();
}
}
示例2: _list
/**
* List users.
*
* @subcommand list
* @synopsis [--role=<role>] [--ids]
*/
public function _list($args, $assoc_args)
{
global $blog_id;
$params = array('blog_id' => $blog_id, 'fields' => isset($assoc_args['ids']) ? 'ids' : 'all_with_meta');
if (array_key_exists('role', $assoc_args)) {
$params['role'] = $assoc_args['role'];
}
$users = get_users($params);
if (isset($assoc_args['ids'])) {
WP_CLI::out(implode(' ', $users));
return;
}
$fields = array('ID', 'user_login', 'display_name', 'user_email', 'user_registered');
$table = new \cli\Table();
$table->setHeaders(array_merge($fields, array('roles')));
foreach ($users as $user) {
$line = array();
foreach ($fields as $field) {
$line[] = $user->{$field};
}
$line[] = implode(',', $user->roles);
$table->addRow($line);
}
$table->display();
WP_CLI::line('Total: ' . count($users) . ' users');
}
示例3: single_command_help
private function single_command_help($name, $command)
{
WP_CLI::out(' wp ' . $name);
$methods = WP_CLI_Command::get_subcommands($command);
if (!empty($methods)) {
WP_CLI::out(' [' . implode('|', $methods) . ']');
}
WP_CLI::line(' ...');
}
示例4: confirm
private static function confirm($question, $assoc_args)
{
if (!isset($assoc_args['yes'])) {
WP_CLI::out($question . " [y/n] ");
$answer = trim(fgets(STDIN));
if ('y' != $answer) {
exit;
}
}
}
示例5: reset
/**
* Removes all tables from the database.
*/
function reset($args, $assoc_args)
{
if (!isset($assoc_args['yes'])) {
WP_CLI::out("Are you sure you want to reset the database? [y/n] ");
$answer = trim(fgets(STDIN));
if ('y' != $answer) {
return;
}
}
WP_CLI::launch(self::create_cmd('mysql --host=%s --user=%s --password=%s --execute=%s', DB_HOST, DB_USER, DB_PASSWORD, 'DROP DATABASE IF EXISTS ' . DB_NAME));
WP_CLI::launch(self::create_cmd('mysql --host=%s --user=%s --password=%s --execute=%s', DB_HOST, DB_USER, DB_PASSWORD, 'CREATE DATABASE ' . DB_NAME));
WP_CLI::success("Database reset.");
}
示例6: o
/**
* Print string
*
* @param string $string
*/
protected static function o($string)
{
\WP_CLI::out($string);
}
示例7: fetch_counts
/**
* Pull sharedcount for all posts
*
* ## OPTIONS
*
* [--parallelize=<n_of_m>]
* : Process only every N of M attachments, formatted as N/M. Useful for doing large batches quickly, optimizing the CPU. Wrap in a shell script to iterate 0 < N < M and reap the benefits.
*
*/
function fetch_counts($args, $assoc_args = array())
{
// Clean the output buffer. Not sure why this exists.
ob_end_clean();
// Either every single post...
$every_n = 0;
$of_m = 1;
// Or a set of them to parallelize pages
if (!empty($assoc_args['parallelize']) && preg_match('#^(\\d+)/(\\d+)$#', $assoc_args['parallelize'], $matches)) {
$every_n = (int) $matches[1];
$of_m = (int) $matches[2];
}
$query_args = array('meta_query' => array('relation' => 'OR', array('key' => 'sharedcount_updated', 'type' => 'DATETIME', 'value' => gmdate('Y-m-d H:i:s', time() - 3600), 'compare' => '<'), array('key' => 'sharedcount_updated', 'compare' => 'NOT EXISTS')), 'posts_per_page' => 50, 'paged' => $every_n);
do {
$query = new WP_Query(apply_filters('sharedcount_update_query', $query_args));
foreach ($query->posts as $post) {
$current = (int) get_post_meta($post->ID, 'sharedcount_count', true);
WP_CLI::out("Getting sharecount for {$post->ID} `{$post->post_title}` (current: {$current}) ... ");
$counts = SharedCount::get_counts(get_permalink($post));
if (!empty($counts)) {
$count = (int) $counts['total'];
WP_CLI::out($count . '... ');
if ($current < $count) {
WP_CLI::out(' Updating');
update_post_meta($post->ID, 'sharedcount_count', $count);
}
}
WP_CLI::line();
update_post_meta($post->ID, 'sharedcount_updated', current_time('mysql', true));
}
$query_args['paged'] += $of_m;
} while ($query->max_num_pages > $query_args['paged']);
}
示例8: prompt
/**
* Prompt for some input from the user
*/
private function prompt($message)
{
WP_CLI::out(trim($message) . " ");
return trim(fgets(STDIN));
}