| 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 | * - array $user_ids |
| 1715 | * @return array user_ids |
| 1716 | */ |
| 1717 | function wp_deleteUser( $args ) { |
| 1718 | |
| 1719 | $this->escape( $args ); |
| 1720 | |
| 1721 | $blog_ID = (int) $args[0]; |
| 1722 | $username = $args[1]; |
| 1723 | $password = $args[2]; |
| 1724 | $user_IDs = $args[3]; // can be an array of user ID's |
| 1725 | |
| 1726 | if ( ! $user = $this->login( $username, $password ) ) |
| 1727 | return $this->error; |
| 1728 | |
| 1729 | if( ! current_user_can( 'delete_users' ) ) |
| 1730 | return new IXR_Error( 401, __( 'You are not allowed to delete users.' ) ); |
| 1731 | |
| 1732 | // if only a single ID is given convert it to an array |
| 1733 | if( ! is_array( $user_IDs ) ) |
| 1734 | $user_IDs = array( (int)$user_IDs ); |
| 1735 | |
| 1736 | foreach( $user_IDs as $user_ID ) { |
| 1737 | |
| 1738 | $user_ID = (int) $user_ID; |
| 1739 | |
| 1740 | if( ! get_userdata( $user_ID ) ) |
| 1741 | return new IXR_Error(404, __('Sorry, one of the given user does not exist.')); |
| 1742 | |
| 1743 | if( $user->ID == $user_ID ) |
| 1744 | return new IXR_Error( 401, __( 'You cannot delete yourself.' ) ); |
| 1745 | |
| 1746 | } |
| 1747 | |
| 1748 | // this holds all the id of deleted users and return it |
| 1749 | $deleted_users = array(); |
| 1750 | |
| 1751 | foreach( $user_IDs as $user_ID ) { |
| 1752 | |
| 1753 | $result = wp_delete_user( $user_ID ); |
| 1754 | if ( $result ) |
| 1755 | $deleted_users[] = $user_ID; |
| 1756 | |
| 1757 | } |
| 1758 | |
| 1759 | return $deleted_users; |
| 1760 | |
| 1761 | } |
| 1762 | |