/** * Get a list of comments. * * ## OPTIONS * * [--<field>=<value>] * : One or more args to pass to WP_Comment_Query. * * [--field=<field>] * : Prints the value of a single field for each comment. * * [--fields=<fields>] * : Limit the output to specific object fields. * * [--format=<format>] * : Render output in a particular format. * --- * default: table * options: * - table * - ids * - csv * - json * - count * - yaml * --- * * ## AVAILABLE FIELDS * * These fields will be displayed by default for each comment: * * * comment_ID * * comment_post_ID * * comment_date * * comment_approved * * comment_author * * comment_author_email * * These fields are optionally available: * * * comment_author_url * * comment_author_IP * * comment_date_gmt * * comment_content * * comment_karma * * comment_agent * * comment_type * * comment_parent * * user_id * * url * * ## EXAMPLES * * # List comment IDs. * $ wp comment list --field=ID * 22 * 23 * 24 * * # List comments of a post. * $ wp comment list --post_id=1 --fields=ID,comment_date,comment_author * +------------+---------------------+----------------+ * | comment_ID | comment_date | comment_author | * +------------+---------------------+----------------+ * | 1 | 2015-06-20 09:00:10 | Mr WordPress | * +------------+---------------------+----------------+ * * # List approved comments. * $ wp comment list --number=3 --status=approve --fields=ID,comment_date,comment_author * +------------+---------------------+----------------+ * | comment_ID | comment_date | comment_author | * +------------+---------------------+----------------+ * | 1 | 2015-06-20 09:00:10 | Mr WordPress | * | 30 | 2013-03-14 12:35:07 | John Doe | * | 29 | 2013-03-14 11:56:08 | Jane Doe | * +------------+---------------------+----------------+ * * @subcommand list */ public function list_($_, $assoc_args) { $formatter = $this->get_formatter($assoc_args); if ('ids' == $formatter->format) { $assoc_args['fields'] = 'comment_ID'; } if (!empty($assoc_args['comment__in'])) { $assoc_args['comment__in'] = explode(',', $assoc_args['comment__in']); } if (!empty($assoc_args['comment__in']) && !empty($assoc_args['orderby']) && 'comment__in' === $assoc_args['orderby'] && Utils\wp_version_compare('4.4', '<')) { $comments = array(); foreach ($assoc_args['comment__in'] as $comment_id) { $comment = get_comment($comment_id); if ($comment) { $comments[] = $comment; } else { WP_CLI::warning(sprintf("Invalid comment %s.", $comment_id)); } } } else { $query = new WP_Comment_Query(); $comments = $query->query($assoc_args); } if ('ids' == $formatter->format) { $comments = wp_list_pluck($comments, 'comment_ID'); } else { $comments = array_map(function ($comment) { $comment->url = get_comment_link($comment->comment_ID); return $comment; }, $comments); } $formatter->display_items($comments); }
/** * Load WordPress, if it hasn't already been loaded */ public function load_wordpress() { static $wp_cli_is_loaded; // Globals not explicitly globalized in WordPress global $site_id, $wpdb, $public, $current_site, $current_blog, $path, $shortcode_tags; if (!empty($wp_cli_is_loaded)) { return; } $wp_cli_is_loaded = true; WP_CLI::debug('Begin WordPress load', 'bootstrap'); WP_CLI::do_hook('before_wp_load'); $this->check_wp_version(); $wp_config_path = Utils\locate_wp_config(); if (!$wp_config_path) { WP_CLI::error("'wp-config.php' not found.\n" . "Either create one manually or use `wp core config`."); } WP_CLI::debug('wp-config.php path: ' . $wp_config_path, 'bootstrap'); WP_CLI::do_hook('before_wp_config_load'); // Load wp-config.php code, in the global scope $wp_cli_original_defined_vars = get_defined_vars(); eval($this->get_wp_config_code()); foreach (get_defined_vars() as $key => $var) { if (array_key_exists($key, $wp_cli_original_defined_vars) || 'wp_cli_original_defined_vars' === $key) { continue; } $GLOBALS[$key] = $var; } $this->maybe_update_url_from_domain_constant(); WP_CLI::do_hook('after_wp_config_load'); // Load WP-CLI utilities require WP_CLI_ROOT . '/php/utils-wp.php'; // Set up WordPress bootstrap actions and filters $this->setup_bootstrap_hooks(); // Load Core, mu-plugins, plugins, themes etc. if (Utils\wp_version_compare('4.6-alpha-37575', '>=')) { require ABSPATH . 'wp-settings.php'; } else { require WP_CLI_ROOT . '/php/wp-settings-cli.php'; } // Fix memory limit. See http://core.trac.wordpress.org/ticket/14889 @ini_set('memory_limit', -1); // Load all the admin APIs, for convenience require ABSPATH . 'wp-admin/includes/admin.php'; add_filter('filesystem_method', function () { return 'direct'; }, 99); WP_CLI::debug('Loaded WordPress', 'bootstrap'); WP_CLI::do_hook('after_wp_load'); }
/** * List terms in a taxonomy. * * ## OPTIONS * * <taxonomy>... * : List terms of one or more taxonomies * * [--<field>=<value>] * : Filter by one or more fields (see get_terms() $args parameter for a list of fields). * * [--field=<field>] * : Prints the value of a single field for each term. * * [--fields=<fields>] * : Limit the output to specific object fields. * * [--format=<format>] * : Render output in a particular format. * --- * default: table * options: * - table * - csv * - ids * - json * - count * - yaml * --- * * ## AVAILABLE FIELDS * * These fields will be displayed by default for each term: * * * term_id * * term_taxonomy_id * * name * * slug * * description * * parent * * count * * These fields are optionally available: * * * url * * ## EXAMPLES * * # List post categories * $ wp term list category --format=csv * term_id,term_taxonomy_id,name,slug,description,parent,count * 2,2,aciform,aciform,,0,1 * 3,3,antiquarianism,antiquarianism,,0,1 * 4,4,arrangement,arrangement,,0,1 * 5,5,asmodeus,asmodeus,,0,1 * * # List post tags * $ wp term list post_tag --fields=name,slug * +-----------+-------------+ * | name | slug | * +-----------+-------------+ * | 8BIT | 8bit | * | alignment | alignment-2 | * | Articles | articles | * | aside | aside | * +-----------+-------------+ * * @subcommand list */ public function list_($args, $assoc_args) { foreach ($args as $taxonomy) { if (!taxonomy_exists($taxonomy)) { WP_CLI::error("Taxonomy {$taxonomy} doesn't exist."); } } $formatter = $this->get_formatter($assoc_args); $defaults = array('hide_empty' => false); $assoc_args = array_merge($defaults, $assoc_args); if (!empty($assoc_args['term_id'])) { $term = get_term_by('id', $assoc_args['term_id'], $args[0]); $terms = array($term); } else { if (!empty($assoc_args['include']) && !empty($assoc_args['orderby']) && 'include' === $assoc_args['orderby'] && Utils\wp_version_compare('4.7', '<')) { $terms = array(); $term_ids = explode(',', $assoc_args['include']); foreach ($term_ids as $term_id) { $term = get_term_by('id', $term_id, $args[0]); if ($term && !is_wp_error($term)) { $terms[] = $term; } else { WP_CLI::warning(sprintf("Invalid term %s.", $term_id)); } } } else { $terms = get_terms($args, $assoc_args); } } $terms = array_map(function ($term) { $term->count = (int) $term->count; $term->parent = (int) $term->parent; $term->url = get_term_link($term); return $term; }, $terms); if ('ids' == $formatter->format) { $terms = wp_list_pluck($terms, 'term_id'); echo implode(' ', $terms); } else { $formatter->display_items($terms); } }