Ticket #31746: 31746.3.diff
File 31746.3.diff, 4.7 KB (added by , 9 years ago) |
---|
-
src/wp-includes/user-functions.php
500 500 */ 501 501 function get_blogs_of_user( $user_id, $all = false ) { 502 502 global $wpdb; 503 static $blogs = array(); 503 504 504 505 $user_id = (int) $user_id; 505 506 506 507 // Logged out users can't have blogs 507 if ( empty( $user_id ) ) 508 if ( empty( $user_id ) ) { 508 509 return array(); 510 } 509 511 512 /** 513 * Filter a user's blogs array before it is retrieved. 514 * 515 * @since 4.4 516 * 517 * @param array $blogs[ $user_id ] An array of blog objects belonging to the user. Default null. 518 * @param int $user_id User ID. 519 * @param bool $all Whether the returned blogs array should contain all 520 * blogs, including those marked 'deleted', 'archived', 521 * or 'spam'. Default false. 522 */ 523 $blogs[ $user_id ] = apply_filters( 'pre_get_blogs_of_user', null, $user_id, $all ); 524 525 if ( is_array( $blogs[ $user_id ] ) ) { 526 return $blogs[ $user_id ]; 527 } 528 510 529 $keys = get_user_meta( $user_id ); 511 if ( empty( $keys ) ) 530 if ( empty( $keys ) ) { 512 531 return array(); 532 } 513 533 514 534 if ( ! is_multisite() ) { 515 535 $blog_id = get_current_blog_id(); 516 $blogs = array( $blog_id => new stdClass );517 $blogs[ $ blog_id ]->userblog_id = $blog_id;518 $blogs[ $ blog_id ]->blogname = get_option('blogname');519 $blogs[ $ blog_id ]->domain = '';520 $blogs[ $ blog_id ]->path = '';521 $blogs[ $ blog_id ]->site_id = 1;522 $blogs[ $ blog_id ]->siteurl = get_option('siteurl');523 $blogs[ $ blog_id ]->archived = 0;524 $blogs[ $ blog_id ]->spam = 0;525 $blogs[ $ blog_id ]->deleted = 0;526 return $blogs ;536 $blogs[ $user_id ] = array( $blog_id => new stdClass ); 537 $blogs[ $user_id ][ $blog_id ]->userblog_id = $blog_id; 538 $blogs[ $user_id ][ $blog_id ]->blogname = get_option('blogname'); 539 $blogs[ $user_id ][ $blog_id ]->domain = ''; 540 $blogs[ $user_id ][ $blog_id ]->path = ''; 541 $blogs[ $user_id ][ $blog_id ]->site_id = 1; 542 $blogs[ $user_id ][ $blog_id ]->siteurl = get_option('siteurl'); 543 $blogs[ $user_id ][ $blog_id ]->archived = 0; 544 $blogs[ $user_id ][ $blog_id ]->spam = 0; 545 $blogs[ $user_id ][ $blog_id ]->deleted = 0; 546 return $blogs[ $user_id ]; 527 547 } 528 548 529 $blogs = array();549 $blogs[ $user_id ] = array(); 530 550 531 551 if ( isset( $keys[ $wpdb->base_prefix . 'capabilities' ] ) && defined( 'MULTISITE' ) ) { 532 552 $blog = get_blog_details( 1 ); 533 553 if ( $blog && isset( $blog->domain ) && ( $all || ( ! $blog->archived && ! $blog->spam && ! $blog->deleted ) ) ) { 534 $blogs[ 1 ] = (object) array(554 $blogs[ $user_id ][ 1 ] = (object) array( 535 555 'userblog_id' => 1, 536 556 'blogname' => $blog->blogname, 537 557 'domain' => $blog->domain, … … 561 581 $blog_id = (int) $blog_id; 562 582 $blog = get_blog_details( $blog_id ); 563 583 if ( $blog && isset( $blog->domain ) && ( $all || ( ! $blog->archived && ! $blog->spam && ! $blog->deleted ) ) ) { 564 $blogs[ $ blog_id ] = (object) array(584 $blogs[ $user_id ][ $blog_id ] = (object) array( 565 585 'userblog_id' => $blog_id, 566 586 'blogname' => $blog->blogname, 567 587 'domain' => $blog->domain, … … 581 601 * 582 602 * @since MU 583 603 * 584 * @param array $blogs An array of blog objects belonging to the user. 585 * @param int $user_id User ID. 586 * @param bool $all Whether the returned blogs array should contain all blogs, including 587 * those marked 'deleted', 'archived', or 'spam'. Default false. 604 * @param array $blogs[ $user_id ] An array of blog objects belonging to the user. 605 * @param int $user_id User ID. 606 * @param bool $all Whether the returned blogs array should contain all 607 * blogs, including those marked 'deleted', 'archived', 608 * or 'spam'. Default false. 588 609 */ 589 return apply_filters( 'get_blogs_of_user', $blogs , $user_id, $all );610 return apply_filters( 'get_blogs_of_user', $blogs[ $user_id ], $user_id, $all ); 590 611 } 591 612 592 613 /** -
tests/phpunit/tests/user/multisite.php
106 106 // Passing false (the default) as the second parameter should retrieve only good sites. 107 107 $blog_ids_of_user = array_keys( get_blogs_of_user( $user1_id, false ) ); 108 108 $this->assertEquals( $blog_ids, $blog_ids_of_user ); 109 110 add_filter( 'pre_get_blogs_of_user', '__return_empty_array' ); 111 $blogs_of_user = get_blogs_of_user( $user1_id, false ); 112 113 $this->assertTrue( is_array( $blog_ids ) && empty( $blog_ids ) ); 109 114 } 110 115 111 116 /**