diff --git src/wp-includes/user.php src/wp-includes/user.php
index 1cd2db2..6d89bcb 100644
|
|
|
function get_blogs_of_user( $user_id, $all = false ) { |
| 1270 | 1270 | * @return bool |
| 1271 | 1271 | */ |
| 1272 | 1272 | function is_user_member_of_blog( $user_id = 0, $blog_id = 0 ) { |
| | 1273 | global $wpdb; |
| | 1274 | |
| 1273 | 1275 | $user_id = (int) $user_id; |
| 1274 | 1276 | $blog_id = (int) $blog_id; |
| 1275 | 1277 | |
| 1276 | | if ( empty( $user_id ) ) |
| | 1278 | if ( empty( $user_id ) ) { |
| 1277 | 1279 | $user_id = get_current_user_id(); |
| | 1280 | } |
| | 1281 | |
| | 1282 | //Technically not needed, but does save calls to get_blog_details and get_user_meta |
| | 1283 | //in the event that the function is called when a user isn't logged in |
| | 1284 | if ( empty( $user_id ) ) { |
| | 1285 | return false; |
| | 1286 | } else { |
| | 1287 | $user = get_userdata( $user_id ); |
| | 1288 | if ( ! $user instanceof WP_User ) { |
| | 1289 | return false; |
| | 1290 | } |
| | 1291 | } |
| 1278 | 1292 | |
| 1279 | | if ( empty( $blog_id ) ) |
| | 1293 | if ( ! is_multisite() ) { |
| | 1294 | return true; |
| | 1295 | } |
| | 1296 | |
| | 1297 | if ( empty( $blog_id ) ) { |
| 1280 | 1298 | $blog_id = get_current_blog_id(); |
| | 1299 | } |
| | 1300 | |
| | 1301 | $blog = get_blog_details( $blog_id ); |
| 1281 | 1302 | |
| 1282 | | $blogs = get_blogs_of_user( $user_id ); |
| 1283 | | return array_key_exists( $blog_id, $blogs ); |
| | 1303 | if ( ! $blog || ! isset( $blog->domain ) || $blog->archived || $blog->spam || $blog->deleted ) { |
| | 1304 | return false; |
| | 1305 | } |
| | 1306 | |
| | 1307 | $keys = get_user_meta( $user_id ); |
| | 1308 | if ( empty( $keys ) ) { |
| | 1309 | return false; |
| | 1310 | } |
| | 1311 | |
| | 1312 | //no underscore before capabilities in $base_capabilities_key |
| | 1313 | $base_capabilities_key = $wpdb->base_prefix . 'capabilities'; |
| | 1314 | $site_capabilities_key = $wpdb->base_prefix . $blog_id . '_capabilities'; |
| | 1315 | |
| | 1316 | if ( isset( $keys[ $base_capabilities_key ] ) && $blog_id == 1 ) { |
| | 1317 | return true; |
| | 1318 | } |
| | 1319 | |
| | 1320 | if ( isset( $keys[ $site_capabilities_key ] ) ) { |
| | 1321 | return true; |
| | 1322 | } |
| | 1323 | |
| | 1324 | return false; |
| 1284 | 1325 | } |
| 1285 | 1326 | |
| 1286 | 1327 | /** |
diff --git tests/phpunit/tests/user.php tests/phpunit/tests/user.php
index f63d838..32fe283 100644
|
|
|
class Tests_User extends WP_UnitTestCase { |
| 366 | 366 | function test_is_user_member_of_blog() { |
| 367 | 367 | $old_current = get_current_user_id(); |
| 368 | 368 | |
| | 369 | // test for "get current user" when not logged in |
| | 370 | $this->assertFalse( is_user_member_of_blog() ); |
| | 371 | |
| 369 | 372 | $user_id = $this->factory->user->create( array( 'role' => 'subscriber' ) ); |
| 370 | 373 | wp_set_current_user( $user_id ); |
| 371 | 374 | |
diff --git tests/phpunit/tests/user/multisite.php tests/phpunit/tests/user/multisite.php
index 41b0e88..59cf898 100644
|
|
|
class Tests_Multisite_User extends WP_UnitTestCase { |
| 140 | 140 | function test_is_user_member_of_blog() { |
| 141 | 141 | global $wpdb; |
| 142 | 142 | |
| | 143 | // test for "get current user" when not logged in |
| | 144 | $this->assertFalse( is_user_member_of_blog() ); |
| | 145 | |
| 143 | 146 | $user1_id = $this->factory->user->create( array( 'role' => 'administrator' ) ); |
| 144 | 147 | |
| 145 | 148 | $old_current = get_current_user_id(); |