Make WordPress Core

Ticket #32472: is_user_member_of_blog_(v4).diff

File is_user_member_of_blog_(v4).diff, 1.6 KB (added by BinaryKitten, 8 years ago)

v4 - with coding standards added to phpStorm

  • wp-includes/user.php

    diff --git wp-includes/user.php wp-includes/user.php
    index 9f7cf75..a284f3f 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        global $wpdb;
     1238
     1239        if ( ! is_multisite() ) {
     1240                return true;
     1241        }
     1242
    12371243        $user_id = (int) $user_id;
    12381244        $blog_id = (int) $blog_id;
    12391245
    1240         if ( empty( $user_id ) )
     1246        if ( empty( $user_id ) ) {
    12411247                $user_id = get_current_user_id();
     1248        }
    12421249
    1243         if ( empty( $blog_id ) )
     1250        //Technically not needed, but does save calls to get_blog_details and get_user_meta
     1251        //in the event that the function is called when a user isn't logged in
     1252        if ( empty( $user_id ) ) {
     1253                return false;
     1254        }
     1255
     1256        if ( empty( $blog_id ) ) {
    12441257                $blog_id = get_current_blog_id();
     1258        }
     1259
     1260        $blog = get_blog_details( $blog_id );
    12451261
    1246         $blogs = get_blogs_of_user( $user_id );
    1247         return array_key_exists( $blog_id, $blogs );
     1262        if ( ! $blog || ! isset( $blog->domain ) || $blog->archived || $blog->spam || $blog->deleted ) {
     1263                return false;
     1264        }
     1265
     1266        $keys = get_user_meta( $user_id );
     1267        if ( empty( $keys ) ) {
     1268                return false;
     1269        }
     1270
     1271        //no underscore before capabilities in $base_capabilities_key
     1272        $base_capabilities_key = $wpdb->base_prefix . 'capabilities';
     1273        $site_capabilities_key = $wpdb->base_prefix . $blog_id . '_capabilities';
     1274
     1275        if ( isset( $keys[ $base_capabilities_key ] ) && defined( 'MULTISITE' ) && $blog_id == 1 ) {
     1276                return true;
     1277        }
     1278
     1279        if ( isset( $keys[ $site_capabilities_key ] ) ) {
     1280                return true;
     1281        }
     1282
     1283        return false;
    12481284}
    12491285
    12501286/**