wp_xmlrpc_server::_prepare_user( WP_User $user, array $fields ): array
- Source
wp-includes/class-wp-xmlrpc-server.php:1237
Compatibility
- WordPress
- core
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$userWP_User- The unprepared user object.
$fieldsarray- The subset of user fields to return.
Return value
array- The prepared user data.
Performance profile
How much work a call to wp_xmlrpc_server::_prepare_user() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Trivial
- Scaling
- Constant
- Instructions
- 48–63
- Plugin surface
- 1 hook
- Called by
- 3
Touches nothing outside its own arguments.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 69.
Third-party callbacks on 'xmlrpc_prepare_user' run inside this call, and their cost is not bounded by anything here.
3 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
apply_filters()called directly
What one call costs · 3 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_xmlrpc_server::_prepare_user() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
$fields | 48 | ->_convert_date(), array_merge(), apply_filters() |
!$fields | 58 | ->_convert_date(), array_flip(), array_intersect_key(), array_merge(), apply_filters() |
| always | 63 | ->_convert_date(), array_merge(), array_flip(), array_intersect_key(), array_merge(), apply_filters() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 69 | 48–63 | 2 | |
| 8.5 | 69 | 48–63 | 2 | |
| 8.4 | 69 | 48–63 | 2 | 6 fewer instructions than PHP 8.3 |
| 8.3 | 75 | 51–69 | 2 | |
| 8.2 | 75 | 51–69 | 2 | |
| 8.1 | 75 | 51–69 | 2 | |
| 7.4 | 75 | 51–69 | 2 |
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Hooks and filters fired · 1
One hook fires while wp_xmlrpc_server::_prepare_user() runs, in this order:
- apply_filters( xmlrpc_prepare_user )filterline 1274 (+37 into the body)
Filters XML-RPC-prepared data for the given user.
Uses · 2
- apply_filters()Calls the callback functions that have been added to a filter hook.
- wp_xmlrpc_server::_convert_date()Converts a WordPress date string to an IXR_Date object.
Used by · 3
- wp_xmlrpc_server::wp_getProfile()Retrieves information about the requesting user.
- wp_xmlrpc_server::wp_getUser()Retrieves a user.
- wp_xmlrpc_server::wp_getUsers()Retrieves users.
Source code
protected function _prepare_user( $user, $fields ) { $_user = array( 'user_id' => (string) $user->ID ); $user_fields = array( 'username' => $user->user_login, 'first_name' => $user->user_firstname, 'last_name' => $user->user_lastname, 'registered' => $this->_convert_date( $user->user_registered ), 'bio' => $user->user_description, 'email' => $user->user_email, 'nickname' => $user->nickname, 'nicename' => $user->user_nicename, 'url' => $user->user_url, 'display_name' => $user->display_name, 'roles' => $user->roles, ); if ( in_array( 'all', $fields, true ) ) { $_user = array_merge( $_user, $user_fields ); } else { if ( in_array( 'basic', $fields, true ) ) { $basic_fields = array( 'username', 'email', 'registered', 'display_name', 'nicename' ); $fields = array_merge( $fields, $basic_fields ); } $requested_fields = array_intersect_key( $user_fields, array_flip( $fields ) ); $_user = array_merge( $_user, $requested_fields ); } /** * Filters XML-RPC-prepared data for the given user. * * @since 3.5.0 * * @param array $_user An array of user data. * @param WP_User $user User object. * @param array $fields An array of user fields. */ return apply_filters( 'xmlrpc_prepare_user', $_user, $user, $fields ); }Changelog
Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.9.7 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.