Make WordPress Core

Ticket #32472: is_user_member_of_blog.3.diff

File is_user_member_of_blog.3.diff, 1.7 KB (added by BinaryKitten, 9 years ago)

V3 diff - better base point

  • wp-includes/user.php

    diff --git wp-includes/user.php wp-includes/user.php
    index 9f7cf75..f6e5662 100644
    function get_blogs_of_user( $user_id, $all = false ) { 
    12341234 * @return bool
    12351235 */
    12361236function is_user_member_of_blog( $user_id = 0, $blog_id = 0 ) {
    1237         $user_id = (int) $user_id;
    1238         $blog_id = (int) $blog_id;
     1237    global $wpdb;
    12391238
    1240         if ( empty( $user_id ) )
    1241                 $user_id = get_current_user_id();
     1239    if( ! is_multisite() )
     1240        return true;
    12421241
    1243         if ( empty( $blog_id ) )
    1244                 $blog_id = get_current_blog_id();
     1242    $user_id = (int) $user_id;
     1243    $blog_id = (int) $blog_id;
     1244
     1245    if ( empty( $user_id ) )
     1246        $user_id = get_current_user_id();
     1247
     1248    //Technically not needed, but does save calls to get_blog_details and get_user_meta
     1249    //in the event that the function is called when a user isn't logged in
     1250    if ( empty( $user_id ) )
     1251        return false;
     1252
     1253    if ( empty( $blog_id ) )
     1254        $blog_id = get_current_blog_id();
     1255
     1256    $blog = get_blog_details( $blog_id );
     1257
     1258    if( ! $blog || ! isset( $blog->domain ) || $blog->archived || $blog->spam || $blog->deleted )
     1259        return false;
     1260
     1261    $keys = get_user_meta( $user_id );
     1262    if ( empty( $keys ) )
     1263        return false;
     1264
     1265    //no underscore before capabilities in $base_capabilities_key
     1266    $base_capabilities_key = $wpdb->base_prefix . 'capabilities';
     1267    $site_capabilities_key = $wpdb->base_prefix . $blog_id . '_capabilities';
     1268
     1269    if ( isset( $keys[ $base_capabilities_key ] ) && defined( 'MULTISITE' ) && $blog_id == 1 )
     1270        return true;
     1271
     1272    if ( isset( $keys[ $site_capabilities_key ] ) )
     1273        return true;
    12451274
    1246         $blogs = get_blogs_of_user( $user_id );
    1247         return array_key_exists( $blog_id, $blogs );
     1275    return false;
    12481276}
    12491277
    12501278/**