| 1706 | /** |
| 1707 | * Delete a user |
| 1708 | * |
| 1709 | * @uses wp_delete_user() |
| 1710 | * @param array $args Method parameters. Contains: |
| 1711 | * - int $blog_id |
| 1712 | * - string $username |
| 1713 | * - string $password |
| 1714 | * - int $user_id |
| 1715 | * @return True when user is deleted. |
| 1716 | */ |
| 1717 | function wp_deleteUser($args) { |
| 1718 | $this->escape($args); |
| 1719 | |
| 1720 | $blog_id = (int) $args[0]; |
| 1721 | $username = $args[1]; |
| 1722 | $password = $args[2]; |
| 1723 | $user_id = (int) $args[3]; |
| 1724 | |
| 1725 | if (!$user = $this->login($username, $password)) |
| 1726 | return $this->error; |
| 1727 | |
| 1728 | do_action('xmlrpc_call', 'wp.deleteUser'); |
| 1729 | |
| 1730 | if (!current_user_can('delete_users')) |
| 1731 | return new IXR_Error(401, __('You are not allowed to delete users.')); |
| 1732 | |
| 1733 | if (!get_userdata($user_id)) |
| 1734 | return new IXR_Error(404, __('Invalid user ID.')); |
| 1735 | |
| 1736 | if ($user->ID == $user_id) |
| 1737 | return new IXR_Error(401, __('You cannot delete yourself.')); |
| 1738 | |
| 1739 | if (isset($args[4])) { |
| 1740 | $reassign_id = (int) $args[4]; |
| 1741 | if (!get_userdata($user_id)) |
| 1742 | return new IXR_Error(404, __('Invalid reassign user ID.')); |
| 1743 | if($reassign_id == $user_id) |
| 1744 | return new IXR_Error(404, __('Cannot reassign for a deleting user.')); |
| 1745 | } else { |
| 1746 | $reassign_id = 'novalue'; |
| 1747 | } |
| 1748 | |
| 1749 | $result = wp_delete_user($user_id, $reassign_id); |
| 1750 | |
| 1751 | if (!$result) |
| 1752 | return new IXR_Error(500, __('Cannot delete user.')); |
| 1753 | |
| 1754 | return true; |
| 1755 | } |
| 1756 | |