[wp-trac] [WordPress Trac] #63989: is_user_member_of_blogs fetches all user meta keys
WordPress Trac
noreply at wordpress.org
Tue Sep 16 18:45:00 UTC 2025
#63989: is_user_member_of_blogs fetches all user meta keys
--------------------------+-----------------------------
Reporter: rinatkhaziev | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Users | Version: trunk
Severity: normal | Keywords:
Focuses: performance |
--------------------------+-----------------------------
https://core.trac.wordpress.org/changeset/33771 introduced performance
improvements to is_user_member_of_blog to combat the slowness of
[https://core.trac.wordpress.org/ticket/32472 get_blogs_of_user]
It does so by fetching all meta keys (`$meta_key = ''`). This makes it
challenging to use "get_{$meta_type}_metadata" filter, as there's no good
way to tell which part we want to short-circuit or apply special handling
to.
The proposed approach is to change the logic do check for the specific
blog's capability check name.
Roughly:
{{{#!php
<?php
// No underscore before capabilities in $base_capabilities_key.
$base_capabilities_key = $wpdb->base_prefix . 'capabilities';
$site_capabilities_key = $wpdb->base_prefix . $blog_id .
'_capabilities';
if ( 1 === $blog_id ) {
$has_cap = get_user_meta( $user_id,
$base_capabilities_key, true );
} else {
$has_cap = get_user_meta( $user_id,
$site_capabilities_key, true );
}
return is_array( $has_cap );
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/63989>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list