--- /dev/null
+<?php
+
+namespace WP_CLI;
+
+class FetcherComment extends Fetcher {
+
+ public function get( $arg ) {
+ $comment_id = (int) $arg;
+ $comment = get_comment( $comment_id );
+
+ if ( is_null( $comment ) ) {
+ return false;
+ }
+
+ return $comment;
+ }
+}
+
'comment_author_email',
);
+ public function __construct() {
+ $this->fetcher = new \WP_CLI\FetcherComment( "Comment with ID %s does not exist." );
+ }
+
/**
* Insert a comment.
*
}
private function set_status( $args, $status, $success ) {
- $comment = $this->_fetch_comment( $args );
+ $comment = $this->fetcher->get_check( $args[0] );
$r = wp_set_comment_status( $comment->comment_ID, 'approve', true );
* wp comment exists 1337
*/
public function exists( $args ) {
- if ( $this->_fetch_comment( $args ) ) {
+ if ( $this->fetcher->get( $args[0] ) ) {
WP_CLI::success( "Comment with ID $args[0] exists." );
}
}
-
- /**
- * A helper function fetching a comment object from comment_id.
- */
- private function _fetch_comment( $args ) {
- $comment_id = (int) $args[0];
- $comment = get_comment( $comment_id );
-
- if ( is_null( $comment ) ) {
- WP_CLI::error( "Comment with ID $args[0] does not exist." );
- }
-
- return $comment;
- }
}
WP_CLI::add_command( 'comment', 'Comment_Command' );