Make WordPress Core

Ticket #32472: is_user_member_of_blog.diff

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

Patch for is_user_member_of_blog

  • htdocs/wp-includes/user.php

    diff --git htdocs/wp-includes/user.php htdocs/wp-includes/user.php
    index e602a3e..242bd47 100755
    function get_blogs_of_user( $user_id, $all = false ) { 
    12301230 * @return bool
    12311231 */
    12321232function is_user_member_of_blog( $user_id = 0, $blog_id = 0 ) {
    1233         $user_id = (int) $user_id;
    1234         $blog_id = (int) $blog_id;
     1233    global $wpdb;
    12351234
    1236         if ( empty( $user_id ) )
    1237                 $user_id = get_current_user_id();
     1235    if( ! is_multisite() )
     1236        return true;
    12381237
    1239         if ( empty( $blog_id ) )
    1240                 $blog_id = get_current_blog_id();
     1238    $user_id = (int) $user_id;
     1239    $blog_id = (int) $blog_id;
     1240
     1241    if ( empty( $user_id ) )
     1242        $user_id = get_current_user_id();
     1243
     1244    if ( empty( $user_id ) )
     1245        return false;
     1246
     1247    if ( empty( $blog_id ) )
     1248        $blog_id = get_current_blog_id();
     1249
     1250    $blog = get_blog_details( $blog_id );
     1251
     1252    if( ! $blog || ! isset( $blog->domain ) || $blog->archived || $blog->spam || $blog->deleted )
     1253        return false;
     1254
     1255    $keys = get_user_meta( $user_id );
     1256    if ( empty( $keys ) )
     1257        return false;
     1258
     1259    $base_capabilities_key = $wpdb->base_prefix . 'capabilities';
     1260    $site_capabilities_key = $wpdb->base_prefix . $blog_id . '_capabilities';
     1261
     1262    if ( isset( $keys[ $base_capabilities_key ] ) && defined( 'MULTISITE' ) && $blog_id == 1 )
     1263        return true;
     1264
     1265    if ( isset( $keys[ $site_capabilities_key ] ) )
     1266        return true;
    12411267
    1242         $blogs = get_blogs_of_user( $user_id );
    1243         return array_key_exists( $blog_id, $blogs );
     1268    return false;
    12441269}
    12451270
    12461271/**