WP_User_Query::generate_cache_key( array $args, string $sql ): string
- Since
- 6.3.0
- Source
wp-includes/class-wp-user-query.php:1053
Compatibility
- WordPress
- since 6.3.0
- PHP
- 7.4–8.6-dev
- 6.7.10
- 6.8.11
- 6.9.10
- 7.0.7
- 7.1.3
Present in every tracked release (6.7.10 to 7.1.3), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$argsarray- Query arguments.
$sqlstring- SQL statement.
Return value
string- Cache key.
Performance profile
How much work a call to WP_User_Query::generate_cache_key() 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
- Light
- Scaling
- Constant
- Instructions
- 32–61
- Plugin surface
- None
- Called by
- 1
Only touches the object cache, via wp_cache_get_last_changed().
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 65.
Nothing here hands control to plugin code.
1 place in core call this, so the cost is paid more often than your own code shows.
What it touches
- cacheobject cache
wp_cache_get_last_changed()called directly - regexregular expression over the whole input
preg_split()called directly - hookthird-party callbacks
do_action()one call below WP_User_Query::generate_cache_key()
What one call costs · 36 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_User_Query::generate_cache_key() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!isset($args) && !$args && !$ordersby | 32–35 | ->remove_placeholder_escape(), md5(), wp_cache_get_last_changed() |
!isset($args) | 37–43 | ->remove_placeholder_escape(), md5(), wp_cache_get_last_changed(), wp_cache_get_last_changed() |
isset($args) && !$args && !$ordersby | 38–41 | ->remove_placeholder_escape(), md5(), wp_cache_get_last_changed(), absint() |
!empty($args) && !isset($args) && !$args && !$ordersby | 39 | ->remove_placeholder_escape(), md5(), wp_cache_get_last_changed(), preg_split() |
!isset($args) | 39–45 | ->remove_placeholder_escape(), md5(), wp_cache_get_last_changed(), wp_cache_get_last_changed(), restore_current_blog() |
!isset($args) | 40–46 | ->remove_placeholder_escape(), md5(), wp_cache_get_last_changed(), switch_to_blog(), wp_cache_get_last_changed() |
!isset($args) | 40–46 | ->remove_placeholder_escape(), md5(), wp_cache_get_last_changed(), get_current_blog_id(), wp_cache_get_last_changed() |
!isset($args) | 42–48 | ->remove_placeholder_escape(), md5(), wp_cache_get_last_changed(), switch_to_blog(), wp_cache_get_last_changed(), restore_current_blog() |
!isset($args) | 42–48 | ->remove_placeholder_escape(), md5(), wp_cache_get_last_changed(), get_current_blog_id(), wp_cache_get_last_changed(), restore_current_blog() |
isset($args) | 43–49 | ->remove_placeholder_escape(), md5(), wp_cache_get_last_changed(), absint(), wp_cache_get_last_changed() |
!isset($args) | 43–49 | ->remove_placeholder_escape(), md5(), wp_cache_get_last_changed(), get_current_blog_id(), switch_to_blog(), wp_cache_get_last_changed() |
!empty($args) && !isset($args) | 44–47 | ->remove_placeholder_escape(), md5(), wp_cache_get_last_changed(), preg_split(), wp_cache_get_last_changed() |
24 further outcomes, up to 61 instructions
!empty($args) && isset($args) && !$args && !$ordersby | 45 | ->remove_placeholder_escape(), md5(), wp_cache_get_last_changed(), preg_split(), absint() |
isset($args) | 45–51 | ->remove_placeholder_escape(), md5(), wp_cache_get_last_changed(), absint(), wp_cache_get_last_changed(), restore_current_blog() |
!isset($args) | 45–51 | ->remove_placeholder_escape(), md5(), wp_cache_get_last_changed(), get_current_blog_id(), switch_to_blog(), wp_cache_get_last_changed(), restore_current_blog() |
!empty($args) && !isset($args) | 46–49 | ->remove_placeholder_escape(), md5(), wp_cache_get_last_changed(), preg_split(), wp_cache_get_last_changed(), restore_current_blog() |
isset($args) | 46–52 | ->remove_placeholder_escape(), md5(), wp_cache_get_last_changed(), absint(), switch_to_blog(), wp_cache_get_last_changed() |
isset($args) | 46–52 | ->remove_placeholder_escape(), md5(), wp_cache_get_last_changed(), absint(), get_current_blog_id(), wp_cache_get_last_changed() |
!empty($args) && !isset($args) | 47–50 | ->remove_placeholder_escape(), md5(), wp_cache_get_last_changed(), preg_split(), switch_to_blog(), wp_cache_get_last_changed() |
!empty($args) && !isset($args) | 47–50 | ->remove_placeholder_escape(), md5(), wp_cache_get_last_changed(), preg_split(), get_current_blog_id(), wp_cache_get_last_changed() |
isset($args) | 48–54 | ->remove_placeholder_escape(), md5(), wp_cache_get_last_changed(), absint(), switch_to_blog(), wp_cache_get_last_changed(), restore_current_blog() |
isset($args) | 48–54 | ->remove_placeholder_escape(), md5(), wp_cache_get_last_changed(), absint(), get_current_blog_id(), wp_cache_get_last_changed(), restore_current_blog() |
!empty($args) && !isset($args) | 49–52 | ->remove_placeholder_escape(), md5(), wp_cache_get_last_changed(), preg_split(), switch_to_blog(), wp_cache_get_last_changed(), restore_current_blog() |
!empty($args) && !isset($args) | 49–52 | ->remove_placeholder_escape(), md5(), wp_cache_get_last_changed(), preg_split(), get_current_blog_id(), wp_cache_get_last_changed(), restore_current_blog() |
isset($args) | 49–55 | ->remove_placeholder_escape(), md5(), wp_cache_get_last_changed(), absint(), get_current_blog_id(), switch_to_blog(), wp_cache_get_last_changed() |
!empty($args) && isset($args) | 50–53 | ->remove_placeholder_escape(), md5(), wp_cache_get_last_changed(), preg_split(), absint(), wp_cache_get_last_changed() |
!empty($args) && !isset($args) | 50–53 | ->remove_placeholder_escape(), md5(), wp_cache_get_last_changed(), preg_split(), get_current_blog_id(), switch_to_blog(), wp_cache_get_last_changed() |
isset($args) | 51–57 | ->remove_placeholder_escape(), md5(), wp_cache_get_last_changed(), absint(), get_current_blog_id(), switch_to_blog(), wp_cache_get_last_changed(), restore_current_blog() |
!empty($args) && isset($args) | 52–55 | ->remove_placeholder_escape(), md5(), wp_cache_get_last_changed(), preg_split(), absint(), wp_cache_get_last_changed(), restore_current_blog() |
!empty($args) && !isset($args) | 52–55 | ->remove_placeholder_escape(), md5(), wp_cache_get_last_changed(), preg_split(), get_current_blog_id(), switch_to_blog(), wp_cache_get_last_changed(), restore_current_blog() |
!empty($args) && isset($args) | 53–56 | ->remove_placeholder_escape(), md5(), wp_cache_get_last_changed(), preg_split(), absint(), switch_to_blog(), wp_cache_get_last_changed() |
!empty($args) && isset($args) | 53–56 | ->remove_placeholder_escape(), md5(), wp_cache_get_last_changed(), preg_split(), absint(), get_current_blog_id(), wp_cache_get_last_changed() |
!empty($args) && isset($args) | 55–58 | ->remove_placeholder_escape(), md5(), wp_cache_get_last_changed(), preg_split(), absint(), switch_to_blog(), wp_cache_get_last_changed(), restore_current_blog() |
!empty($args) && isset($args) | 55–58 | ->remove_placeholder_escape(), md5(), wp_cache_get_last_changed(), preg_split(), absint(), get_current_blog_id(), wp_cache_get_last_changed(), restore_current_blog() |
!empty($args) && isset($args) | 56–59 | ->remove_placeholder_escape(), md5(), wp_cache_get_last_changed(), preg_split(), absint(), get_current_blog_id(), switch_to_blog(), wp_cache_get_last_changed() |
!empty($args) && isset($args) | 58–61 | ->remove_placeholder_escape(), md5(), wp_cache_get_last_changed(), preg_split(), absint(), get_current_blog_id(), switch_to_blog(), wp_cache_get_last_changed(), restore_current_blog() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 65 | 32–61 | 8 | |
| 8.5 | 65 | 32–61 | 8 | |
| 8.4 | 65 | 32–61 | 8 | 3 fewer instructions than PHP 8.3 |
| 8.3 | 68 | 35–64 | 8 | |
| 8.2 | 68 | 35–64 | 8 | |
| 8.1 | 68 | 35–64 | 8 | |
| 7.4 | 68 | 35–64 | 8 |
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.
Uses · 5
- wp_cache_get_last_changed()Gets last changed date for the specified cache group.
- absint()Converts a value to non-negative integer.
- get_current_blog_id()Retrieves the current site ID.
- switch_to_blog()Switches the current blog.
- restore_current_blog()Restores the current blog, after calling switch_to_blog().
Used by · 1
- WP_User_Query::query()Executes the query, with the current variables.
Source code
protected function generate_cache_key( array $args, $sql ) { global $wpdb; // Replace wpdb placeholder in the SQL statement used by the cache key. $sql = $wpdb->remove_placeholder_escape( $sql ); $key = md5( $sql ); $last_changed = wp_cache_get_last_changed( 'users' ); if ( empty( $args['orderby'] ) ) { // Default order is by 'user_login'. $ordersby = array( 'user_login' => '' ); } elseif ( is_array( $args['orderby'] ) ) { $ordersby = $args['orderby']; } else { // 'orderby' values may be a comma- or space-separated list. $ordersby = preg_split( '/[,\s]+/', $args['orderby'] ); } $blog_id = 0; if ( isset( $args['blog_id'] ) ) { $blog_id = absint( $args['blog_id'] ); } if ( $args['has_published_posts'] || in_array( 'post_count', $ordersby, true ) ) { $switch = $blog_id && get_current_blog_id() !== $blog_id; if ( $switch ) { switch_to_blog( $blog_id ); } $last_changed .= wp_cache_get_last_changed( 'posts' ); if ( $switch ) { restore_current_blog(); } } return "get_users:$key:$last_changed"; }Changelog
Introduced in 6.3.0. 2 changes between 6.7.10 and 7.1.3.
Signature, return type and hooks compared across 5 parsed releases.
$deprecated added.verified against source$args removed.verified against sourceAbout this page
- Parsed data
- Generated from the wordpress-develop 6.7.10 tag, from
src/wp-includes/class-wp-user-query.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.