From 5eb3c0824bd8b0d7b2226a6f46c4ab42ce7e4ef6 Mon Sep 17 00:00:00 2001 From: Daniel Bachhuber Date: Mon, 19 Aug 2013 23:02:36 -0700 Subject: [PATCH] Implement `wp comment get` --- php/commands/comment.php | 50 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/php/commands/comment.php b/php/commands/comment.php index a5b696ae..dd747301 100644 --- a/php/commands/comment.php +++ b/php/commands/comment.php @@ -44,6 +44,56 @@ class Comment_Command extends WP_CLI_Command { } /** + * Get a comment + * + * ## OPTIONS + * + * + * : The comment to get. + * + * * --format= + * : The format to use when printing the comment, acceptable values: + * + * - **table**: Outputs all fields of the comment as a table. + * + * - **json**: Outputs all fields in JSON format. + * + * ## EXAMPLES + * + * wp comment get 1 + * + * @synopsis [--format=] + */ + public function get( $args, $assoc_args ) { + + $defaults = array( + 'format' => 'table' + ); + $assoc_args = array_merge( $defaults, $assoc_args ); + + $comment_id = (int)$args[0]; + $comment = get_comment( $comment_id ); + if ( empty( $comment ) ) + WP_CLI::error( "Invalid comment ID." ); + + switch ( $assoc_args['format'] ) { + + case 'table': + $fields = get_object_vars( $comment ); + \WP_CLI\Utils\assoc_array_to_table( $fields ); + break; + + case 'json': + WP_CLI::print_value( $comment, $assoc_args ); + break; + + default: + \WP_CLI::error( "Invalid format: " . $assoc_args['format'] ); + break; + } + } + + /** * Delete a comment. * * ## OPTIONS -- 2.11.0