wppaste
WordPress

wp_xmlrpc_server::wp_getUsers( array $args ): array|IXR_Error

Source
wp-includes/class-wp-xmlrpc-server.php:2758
Retrieves users.

Description

The optional $filter parameter modifies the query used to retrieve users.Accepted keys are 'number' (default: 50), 'offset' (default: 0), 'role', 'who', 'orderby', and 'order'. The optional $fields parameter specifies what fields will be included in the response array.

Parameters

$argsarray
Method arguments. Note: arguments must be ordered as documented.
  • $0int

    Blog ID (unused).
  • $1string

    Username.
  • $2string

    Password.
  • $3array

    Optional. Arguments for the user query.
  • $4array

    Optional. Fields to return.

Return

array|IXR_Error
users data

Hooks fired · 2

2 hooks fire while wp_xmlrpc_server::wp_getUsers() runs, in this order:

  1. apply_filters( xmlrpc_default_user_fields )filterline 2773 (+15 into the body)

    Filters the default user query fields used by the given XML-RPC method.

  2. do_action( xmlrpc_call )actionline 2782 (+24 into the body)

    Fires after the XML-RPC user has been authenticated but before the rest of the method logic begins.

Uses · 12

Source

	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' );		} 		$user = $this->login( $username, $password );		if ( ! $user ) {			return $this->error;		} 		/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */		do_action( 'xmlrpc_call', 'wp.getUsers', $args, $this ); 		if ( ! current_user_can( 'list_users' ) ) {			return new IXR_Error( 401, __( 'Sorry, you are not allowed to list 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, __( 'Invalid role.' ) );			} 			$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;	}

History

Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 6.8.8 tag, from src/wp-includes/class-wp-xmlrpc-server.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.