[wp-trac] [WordPress Trac] #63989: is_user_member_of_blogs fetches all user meta keys
WordPress Trac
noreply at wordpress.org
Fri Sep 19 08:58:18 UTC 2025
#63989: is_user_member_of_blogs fetches all user meta keys
--------------------------+--------------------------
Reporter: rinatkhaziev | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: 6.9
Component: Users | Version: trunk
Severity: normal | Resolution:
Keywords: has-patch | Focuses: performance
--------------------------+--------------------------
Changes (by SergeyBiryukov):
* milestone: Awaiting Review => 6.9
Old description:
> 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 );
> }}}
New description:
[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#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list