| 1706 | /** |
| 1707 | * Retrieve users |
| 1708 | * |
| 1709 | * @uses get_users() |
| 1710 | * @param array $args Method parameters. Contains: |
| 1711 | * - int $blog_id |
| 1712 | * - string $username |
| 1713 | * - string $password |
| 1714 | * - array $filter optional |
| 1715 | * @return array contatins: |
| 1716 | * - 'ID' |
| 1717 | * - 'user_login' |
| 1718 | * - 'user_registered' |
| 1719 | * - 'user_email' |
| 1720 | * - 'user_url' |
| 1721 | * - 'display_name' |
| 1722 | * - 'user_nicename' |
| 1723 | */ |
| 1724 | function wp_getUsers( $args ) { |
| 1725 | |
| 1726 | global $wp_roles; |
| 1727 | $this->escape( $args ); |
| 1728 | |
| 1729 | $blog_ID = (int) $args[0]; |
| 1730 | $username = $args[1]; |
| 1731 | $password = $args[2]; |
| 1732 | $filter = $args[3]; |
| 1733 | |
| 1734 | if ( ! $user = $this->login( $username, $password ) ) |
| 1735 | return $this->error; |
| 1736 | |
| 1737 | if( ! current_user_can( 'edit_users' )) |
| 1738 | return new IXR_Error( 401, __( 'Sorry, you cannot edit this users.' ) ); |
| 1739 | |
| 1740 | $query = array(); |
| 1741 | |
| 1742 | if ( isset( $filter['role'] ) ) { |
| 1743 | |
| 1744 | if( ! isset ( $wp_roles ) ) |
| 1745 | $wp_roles = new WP_Roles (); |
| 1746 | if( ! array_key_exists( $filter['role'], $wp_roles->get_names() ) ) |
| 1747 | return new IXR_Error( 403, __( 'The role specified is not valid' ) ); |
| 1748 | $query['role'] = $filter['role']; |
| 1749 | |
| 1750 | } |
| 1751 | |
| 1752 | $query['number'] = 50; // default value for querying users |
| 1753 | if ( isset( $filter['numberusers'] ) ) |
| 1754 | $query['number'] = absint( $filter['numberusers'] ); |
| 1755 | |
| 1756 | $users = get_users( $query ); |
| 1757 | |
| 1758 | if ( ! $users ) |
| 1759 | return array( ); |
| 1760 | |
| 1761 | // holds all the user data |
| 1762 | $struct = array(); |
| 1763 | |
| 1764 | foreach ( $users as $user_data ) { |
| 1765 | |
| 1766 | $user_data = (array) $user_data; |
| 1767 | |
| 1768 | $struct[] = array( |
| 1769 | 'ID' => $user_data['ID'], |
| 1770 | 'user_login' => $user_data['user_login'], |
| 1771 | 'user_registered' => $user_data['user_registered'], |
| 1772 | 'user_email' => $user_data['user_email'], |
| 1773 | 'user_url' => $user_data['user_url'], |
| 1774 | 'display_name' => $user_data['display_name'], |
| 1775 | 'user_nicename' => $user_data['user_nicename'], |
| 1776 | |
| 1777 | ); |
| 1778 | |
| 1779 | } |
| 1780 | |
| 1781 | return $struct; |
| 1782 | |
| 1783 | } |
| 1784 | |