+ * The optional $fields parameter specifies what fields will be included
+ * in the response array.
+ *
+ * @uses get_users()
+ * @see wp_getUser() for more on $fields and return values
+ *
+ * @param array $args {
+ * Method arguments. Note: arguments must be ordered as documented.
+ *
+ * @type int $blog_id (unused)
+ * @type string $username
+ * @type string $password
+ * @type array $filter (optional)
+ * @type array $fields (optional)
+ * }
+ * @return array|IXR_Error users data
+ */
+ public function wp_getUsers( $args ) {
+ if ( ! $this->minimum_args( $args, 3 ) )
+ return $this->error;
+
+ $this->escape( $args );
+
+ $username = $args[1];
+ $password = $args[2];
+ $filter = isset( $args[3] ) ? $args[3] : array();
+
+ if ( isset( $args[4] ) ) {
+ $fields = $args[4];
+ } else {
+ /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
+ $fields = apply_filters( 'xmlrpc_default_user_fields', array( 'all' ), 'wp.getUsers' );
+ }
+
+ if ( ! $user = $this->login( $username, $password ) )
+ return $this->error;
+
+ /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
+ do_action( 'xmlrpc_call', 'wp.getUsers' );
+
+ if ( ! current_user_can( 'list_users' ) )
+ return new IXR_Error( 401, __( 'Sorry, you are not allowed to browse users.' ) );
+
+ $query = array( 'fields' => 'all_with_meta' );
+
+ $query['number'] = ( isset( $filter['number'] ) ) ? absint( $filter['number'] ) : 50;
+ $query['offset'] = ( isset( $filter['offset'] ) ) ? absint( $filter['offset'] ) : 0;
+
+ if ( isset( $filter['orderby'] ) ) {
+ $query['orderby'] = $filter['orderby'];
+
+ if ( isset( $filter['order'] ) )
+ $query['order'] = $filter['order'];
+ }
+
+ if ( isset( $filter['role'] ) ) {
+ if ( get_role( $filter['role'] ) === null )
+ return new IXR_Error( 403, __( 'The role specified is not valid' ) );
+
+ $query['role'] = $filter['role'];
+ }
+
+ if ( isset( $filter['who'] ) ) {
+ $query['who'] = $filter['who'];
+ }
+
+ $users = get_users( $query );
+
+ $_users = array();
+ foreach ( $users as $user_data ) {
+ if ( current_user_can( 'edit_user', $user_data->ID ) )
+ $_users[] = $this->_prepare_user( $user_data, $fields );
+ }
+ return $_users;
+ }
+
+ /**
+ * Retrieve information about the requesting user.
+ *
+ * @uses get_userdata()
+ *
+ * @param array $args {
+ * Method arguments. Note: arguments must be ordered as documented.
+ *
+ * @type int $blog_id (unused)
+ * @type string $username
+ * @type string $password
+ * @type array $fields (optional)
+ * }
+ * @return array|IXR_Error (@see wp_getUser)
+ */
+ public function wp_getProfile( $args ) {
+ if ( ! $this->minimum_args( $args, 3 ) )
+ return $this->error;
+
+ $this->escape( $args );
+
+ $username = $args[1];
+ $password = $args[2];
+
+ if ( isset( $args[3] ) ) {
+ $fields = $args[3];
+ } else {
+ /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
+ $fields = apply_filters( 'xmlrpc_default_user_fields', array( 'all' ), 'wp.getProfile' );
+ }
+
+ if ( ! $user = $this->login( $username, $password ) )
+ return $this->error;
+
+ /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
+ do_action( 'xmlrpc_call', 'wp.getProfile' );
+
+ if ( ! current_user_can( 'edit_user', $user->ID ) )
+ return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit your profile.' ) );
+
+ $user_data = get_userdata( $user->ID );
+
+ return $this->_prepare_user( $user_data, $fields );
+ }
+
+ /**
+ * Edit user's profile.
+ *
+ * @uses wp_update_user()
+ *
+ * @param array $args {
+ * Method arguments. Note: arguments must be ordered as documented.
+ *
+ * @type int $blog_id (unused)
+ * @type string $username
+ * @type string $password
+ * @type array $content_struct It can optionally contain:
+ * - 'first_name'
+ * - 'last_name'
+ * - 'website'
+ * - 'display_name'
+ * - 'nickname'
+ * - 'nicename'
+ * - 'bio'
+ * }
+ * @return true|IXR_Error True, on success.
+ */
+ public function wp_editProfile( $args ) {
+ if ( ! $this->minimum_args( $args, 4 ) )
+ return $this->error;
+
+ $this->escape( $args );
+
+ $username = $args[1];
+ $password = $args[2];
+ $content_struct = $args[3];
+
+ if ( ! $user = $this->login( $username, $password ) )
+ return $this->error;
+
+ /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
+ do_action( 'xmlrpc_call', 'wp.editProfile' );
+
+ if ( ! current_user_can( 'edit_user', $user->ID ) )
+ return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit your profile.' ) );
+
+ // holds data of the user
+ $user_data = array();
+ $user_data['ID'] = $user->ID;
+
+ // only set the user details if it was given
+ if ( isset( $content_struct['first_name'] ) )
+ $user_data['first_name'] = $content_struct['first_name'];
+
+ if ( isset( $content_struct['last_name'] ) )
+ $user_data['last_name'] = $content_struct['last_name'];
+
+ if ( isset( $content_struct['url'] ) )
+ $user_data['user_url'] = $content_struct['url'];
+
+ if ( isset( $content_struct['display_name'] ) )
+ $user_data['display_name'] = $content_struct['display_name'];
+
+ if ( isset( $content_struct['nickname'] ) )
+ $user_data['nickname'] = $content_struct['nickname'];
+
+ if ( isset( $content_struct['nicename'] ) )
+ $user_data['user_nicename'] = $content_struct['nicename'];
+
+ if ( isset( $content_struct['bio'] ) )
+ $user_data['description'] = $content_struct['bio'];
+
+ $result = wp_update_user( $user_data );
+
+ if ( is_wp_error( $result ) )
+ return new IXR_Error( 500, $result->get_error_message() );
+
+ if ( ! $result )
+ return new IXR_Error( 500, __( 'Sorry, the user cannot be updated.' ) );
+
+ return true;
+ }
+
+ /**
+ * Retrieve page.
+ *
+ * @since 2.2.0
+ *
+ * @param array $args {
+ * Method arguments. Note: arguments must be ordered as documented.
+ *
+ * @type int $blog_id (unused)
+ * @type int $page_id
+ * @type string $username
+ * @type string $password
+ * }
+ * @return array|IXR_Error
+ */
+ public function wp_getPage( $args ) {
+ $this->escape( $args );
+
+ $page_id = (int) $args[1];
+ $username = $args[2];
+ $password = $args[3];
+
+ if ( !$user = $this->login($username, $password) ) {
+ return $this->error;
+ }
+
+ $page = get_post($page_id);
+ if ( ! $page )
+ return new IXR_Error( 404, __( 'Invalid post ID.' ) );
+
+ if ( !current_user_can( 'edit_page', $page_id ) )
+ return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this page.' ) );
+
+ /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
+ do_action( 'xmlrpc_call', 'wp.getPage' );
+
+ // If we found the page then format the data.
+ if ( $page->ID && ($page->post_type == 'page') ) {
+ return $this->_prepare_page( $page );
+ }
+ // If the page doesn't exist indicate that.
+ else {
+ return new IXR_Error( 404, __( 'Sorry, no such page.' ) );
+ }
+ }
+
+ /**
+ * Retrieve Pages.
+ *
+ * @since 2.2.0
+ *
+ * @param array $args {
+ * Method arguments. Note: arguments must be ordered as documented.
+ *
+ * @type int $blog_id (unused)
+ * @type string $username
+ * @type string $password
+ * @type int $num_pages
+ * }
+ * @return array|IXR_Error
+ */
+ public function wp_getPages( $args ) {
+ $this->escape( $args );
+
+ $username = $args[1];
+ $password = $args[2];
+ $num_pages = isset($args[3]) ? (int) $args[3] : 10;