예제 #1
0
 /**
  * Delete a comment.
  *
  * ## OPTIONS
  *
  * <id>...
  * : One or more IDs of comments to delete.
  *
  * [--force]
  * : Skip the trash bin.
  *
  * ## EXAMPLES
  *
  *     # Delete comment
  *     $ wp comment delete 1337 --force
  *     Success: Deleted comment 1337.
  *
  *     # Delete multiple comments
  *     $ wp comment delete 1337 2341 --force
  *     Success: Deleted comment 1337.
  *     Success: Deleted comment 2341.
  */
 public function delete($args, $assoc_args)
 {
     parent::_delete($args, $assoc_args, function ($comment_id, $assoc_args) {
         $force = \WP_CLI\Utils\get_flag_value($assoc_args, 'force');
         $status = wp_get_comment_status($comment_id);
         $r = wp_delete_comment($comment_id, $force);
         if ($r) {
             if ($force || 'trash' === $status) {
                 return array('success', "Deleted comment {$comment_id}.");
             } else {
                 return array('success', "Trashed comment {$comment_id}.");
             }
         } else {
             return array('error', "Failed deleting comment {$comment_id}.");
         }
     });
 }
예제 #2
0
 /**
  * Delete one or more users from the current site.
  *
  * ## OPTIONS
  *
  * <user>...
  * : The user login, user email, or user ID of the user(s) to delete.
  *
  * [--network]
  * : On multisite, delete the user from the entire network.
  *
  * [--reassign=<user-id>]
  * : User ID to reassign the posts to.
  *
  * [--yes]
  * : Answer yes to any confirmation prompts.
  *
  * ## EXAMPLES
  *
  *     # Delete user 123 and reassign posts to user 567
  *     $ wp user delete 123 --reassign=567
  *     Success: Removed user 123 from http://example.com
  */
 public function delete($args, $assoc_args)
 {
     $network = \WP_CLI\Utils\get_flag_value($assoc_args, 'network') && is_multisite();
     $reassign = \WP_CLI\Utils\get_flag_value($assoc_args, 'reassign');
     if ($network && $reassign) {
         WP_CLI::error('Reassigning content to a different user is not supported on multisite.');
     }
     if (!$reassign) {
         WP_CLI::confirm('--reassign parameter not passed. All associated posts will be deleted. Proceed?', $assoc_args);
     }
     $users = $this->fetcher->get_many($args);
     parent::_delete($users, $assoc_args, function ($user) use($network, $reassign) {
         $user_id = $user->ID;
         if ($network) {
             $r = wpmu_delete_user($user_id);
             $message = "Deleted user {$user_id}.";
         } else {
             $r = wp_delete_user($user_id, $reassign);
             $message = "Removed user {$user_id} from " . home_url() . ".";
         }
         if ($r) {
             return array('success', $message);
         } else {
             return array('error', "Failed deleting user {$user_id}.");
         }
     });
 }
예제 #3
0
 /**
  * Delete a comment.
  *
  * ## OPTIONS
  *
  * <id>...
  * : One or more IDs of comments to delete.
  *
  * [--force]
  * : Skip the trash bin.
  *
  * ## EXAMPLES
  *
  *     wp comment delete 1337 --force
  *
  *     wp comment delete 1337 2341 --force
  */
 public function delete($args, $assoc_args)
 {
     parent::_delete($args, $assoc_args, function ($comment_id, $assoc_args) {
         $r = wp_delete_comment($comment_id, \WP_CLI\Utils\get_flag_value($assoc_args, 'force'));
         if ($r) {
             return array('success', "Deleted comment {$comment_id}.");
         } else {
             return array('error', "Failed deleting comment {$comment_id}");
         }
     });
 }
예제 #4
0
파일: post.php 프로젝트: gilbitron/wp-cli
 /**
  * Delete a post by ID.
  *
  * ## OPTIONS
  *
  * <id>...
  * : One or more IDs of posts to delete.
  *
  * [--force]
  * : Skip the trash bin.
  *
  * [--defer-term-counting]
  * : Recalculate term count in batch, for a performance boost.
  *
  * ## EXAMPLES
  *
  *     wp post delete 123 --force
  *
  *     wp post delete $(wp post list --post_type='page' --format=ids)
  *
  *     # delete all posts in the trash
  *     wp post delete $(wp post list --post_status=trash --format=ids)
  */
 public function delete($args, $assoc_args)
 {
     $defaults = array('force' => false);
     $assoc_args = array_merge($defaults, $assoc_args);
     parent::_delete($args, $assoc_args, function ($post_id, $assoc_args) {
         $status = get_post_status($post_id);
         $r = wp_delete_post($post_id, $assoc_args['force']);
         if ($r) {
             $action = $assoc_args['force'] || 'trash' === $status ? 'Deleted' : 'Trashed';
             return array('success', "{$action} post {$post_id}.");
         } else {
             return array('error', "Failed deleting post {$post_id}.");
         }
     });
 }
예제 #5
0
 /**
  * Delete a comment.
  *
  * ## OPTIONS
  *
  * <id>...
  * : One or more IDs of comments to delete.
  *
  * [--force]
  * : Skip the trash bin.
  *
  * ## EXAMPLES
  *
  *     wp comment delete 1337 --force
  *
  *     wp comment delete 1337 2341 --force
  */
 public function delete($args, $assoc_args)
 {
     parent::_delete($args, $assoc_args, function ($comment_id, $assoc_args) {
         $r = wp_delete_comment($comment_id, isset($assoc_args['force']));
         if ($r) {
             return array('success', "Deleted comment {$comment_id}.");
         } else {
             return array('error', "Failed deleting comment {$comment_id}");
         }
     });
 }
예제 #6
0
파일: user.php 프로젝트: nb/wp-cli
 /**
  * Delete one or more users.
  *
  * ## OPTIONS
  *
  * <user>...
  * : The user login, user email, or user ID of the user(s) to update.
  *
  * [--reassign=<user-id>]
  * : User ID to reassign the posts to.
  *
  * ## EXAMPLES
  *
  *     wp user delete 123 --reassign=567
  */
 public function delete($args, $assoc_args)
 {
     $assoc_args = wp_parse_args($assoc_args, array('reassign' => null));
     $users = $this->fetcher->get_many($args);
     parent::_delete($users, $assoc_args, function ($user, $assoc_args) {
         $user_id = $user->ID;
         if (is_multisite()) {
             $r = wpmu_delete_user($user_id);
         } else {
             $r = wp_delete_user($user_id, $assoc_args['reassign']);
         }
         if ($r) {
             return array('success', "Deleted user {$user_id}.");
         } else {
             return array('error', "Failed deleting user {$user_id}.");
         }
     });
 }