wp.getUsers XML-RPC method is returning only 50 users, how can i get all the users

I’m unable to find a XML-RPC method called wp.getUsers in wp-includes/class-wp-xmlrpc-server.php. Could it be, that you’re using an additional plugin that extends the basic behavior of WordPress?

A simple google search for ‘wp.getUsers’ points me to the the github repo of Max Cutler and the class wp-xmlrpc-modernization. There you have a method wp.getUsers which accepts a filter array as 4th parameter.

The optional $filter parameter modifies the query used to retrieve users.
* Accepted keys are ‘number’ (default: 50), ‘offset’ (default: 0), and ‘role’.

EDIT

wp.getUsers is using get_users / WP_Users_Query in the background. Therefore you have to set the number parameter to false if you don’t want a LIMIT clause in the SQL statement.

Here is a snippet from the WP_Users_Query class which builts the SQL statement based on the parameters.

    // limit
    if ( $qv['number'] ) {
        if ( $qv['offset'] )
            $this->query_limit = $wpdb->prepare("LIMIT %d, %d", $qv['offset'], $qv['number']);
        else
            $this->query_limit = $wpdb->prepare("LIMIT %d", $qv['number']);
    }

Unfortunately the wp-xmlrpc-modernization plugin filters the parameter number with the function absint which sanitize a boolean into an integer. You have to edit the plugin and remove/change this filter on line 808.

$query['number'] = ( isset( $filter['number'] ) ) ? absint( $filter['number'] ) : 50;

Leave a Comment