[wp-trac] [WordPress Trac] #59011: Fatal error on single-site get_users() under certain circumstances
WordPress Trac
noreply at wordpress.org
Wed Aug 9 01:36:09 UTC 2023
#59011: Fatal error on single-site get_users() under certain circumstances
--------------------------+--------------------
Reporter: dd32 | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: 6.3.1
Component: Users | Version: 6.3
Severity: normal | Keywords:
Focuses: |
--------------------------+--------------------
The following error was triggered via wp-themes.com today:
{{{
E_ERROR: Uncaught Error: Call to undefined function switch_to_blog() in
wp-includes/class-wp-user-query.php:1077
}}}
This seems to stem from #40613 [55657] (cc @spacedmonkey).
The theme code that triggered it was this:
https://themes.trac.wordpress.org/browser/sequel/1.0.4/functions.php?marks=185-190#L176
{{{
$contributor_ids = get_users( array(
'fields' => 'ID',
'orderby' => 'post_count',
'order' => 'DESC',
'who' => 'authors',
) );
}}}
Note that no `blog_id` is specified, as a result it's prefilled with
`get_current_blog_id()` which return `1` on single-site.
https://github.com/WordPress/wordpress-develop/blob/trunk/src/wp-includes
/class-wp-user-query.php#L94
The `$blog_id` is then initialised to 0 in several places to assume no-
blog or a not-blog-specific request, such as [https://github.com/WordPress
/wordpress-develop/blob/trunk/src/wp-includes/class-wp-user-
query.php#L339-L344 this] but then it hits the problematic code
[https://github.com/WordPress/wordpress-develop/blob/trunk/src/wp-includes
/class-wp-user-query.php#L1070-L1078 here]
The actual issue is this:
> ` if ( ( $args['has_published_posts'] && $blog_id ) || in_array(
'post_count', $ordersby, true ) ) {`
It enters a branch that tries to switch, as `( $blog_id = 0 ) !=
get_current_blog_id()`.
Setting to 6.3.1 for review, as this seems like a regression.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/59011>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list