From f106155bf8754c558691909aa216361eac3b1ba8 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Thu, 10 Aug 2023 10:26:19 +0000 Subject: [PATCH] Users: Correct the logic for `switch_to_blog()` in `WP_User_Query::generate_cache_key()`. If `$blog_id` equals `0`, it should be treated as the current site ID, and there is no need to switch to a different site. This commit prevents an unnecessary call to `switch_to_blog()` on single site to avoid a fatal error when using `'orderby' => 'post_count'` and the deprecated `'who' => 'authors'` parameter: {{{ Uncaught Error: Call to undefined function switch_to_blog() in wp-includes/class-wp-user-query.php:1077 }}} Follow-up to [55657]. Props dd32, austinginder, RavanH, mukesh27. Fixes #59011. Built from https://develop.svn.wordpress.org/trunk@56381 git-svn-id: http://core.svn.wordpress.org/trunk@55893 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/class-wp-user-query.php | 7 +++++-- wp-includes/version.php | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/wp-includes/class-wp-user-query.php b/wp-includes/class-wp-user-query.php index 04f13430f5..c5d66404ea 100644 --- a/wp-includes/class-wp-user-query.php +++ b/wp-includes/class-wp-user-query.php @@ -1071,12 +1071,15 @@ class WP_User_Query { if ( isset( $args['blog_id'] ) ) { $blog_id = absint( $args['blog_id'] ); } - if ( ( $args['has_published_posts'] && $blog_id ) || in_array( 'post_count', $ordersby, true ) ) { - $switch = get_current_blog_id() !== $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(); } diff --git a/wp-includes/version.php b/wp-includes/version.php index 7618d87979..db7bfe70c2 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.4-alpha-56380'; +$wp_version = '6.4-alpha-56381'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.