Ticket #37061: 37061.2.diff
File 37061.2.diff, 6.1 KB (added by , 7 years ago) |
---|
-
src/wp-includes/user.php
559 559 } 560 560 561 561 /** 562 * Get the blogs a user belongs to.562 * Get the sites a user belongs to. 563 563 * 564 564 * @since 3.0.0 565 565 * 566 * @internal In 4.7.0, converted to use get_sites() 567 * 566 568 * @global wpdb $wpdb WordPress database abstraction object. 567 569 * 568 570 * @param int $user_id User ID 569 * @param bool $all Whether to retrieve all blogs, or only blogs that are not571 * @param bool $all Whether to retrieve all sites, or only sites that are not 570 572 * marked as deleted, archived, or spam. 571 * @return array A list of the user's blogs. An empty array if the user doesn't exist572 * or belongs to no blogs.573 * @return array A list of the user's sites. An empty array if the user doesn't exist 574 * or belongs to no sites. 573 575 */ 574 576 function get_blogs_of_user( $user_id, $all = false ) { 575 577 global $wpdb; 576 578 577 579 $user_id = (int) $user_id; 578 580 579 // Logged out users can't have blogs581 // Logged out users can't have sites 580 582 if ( empty( $user_id ) ) 581 583 return array(); 582 584 … … 588 590 * 589 591 * @since 4.6.0 590 592 * 591 * @param null|array $ blogs An array of WP_Site objects of which the user is a member.593 * @param null|array $sites An array of site objects of which the user is a member. 592 594 * @param int $user_id User ID. 593 595 * @param bool $all Whether the returned array should contain all sites, including 594 596 * those marked 'deleted', 'archived', or 'spam'. Default false. 595 597 */ 596 $ blogs = apply_filters( 'pre_get_blogs_of_user', null, $user_id, $all );598 $sites = apply_filters( 'pre_get_blogs_of_user', null, $user_id, $all ); 597 599 598 if ( null !== $ blogs ) {599 return $ blogs;600 if ( null !== $sites ) { 601 return $sites; 600 602 } 601 603 602 604 $keys = get_user_meta( $user_id ); … … 604 606 return array(); 605 607 606 608 if ( ! is_multisite() ) { 607 $ blog_id = get_current_blog_id();608 $ blogs = array( $blog_id => new stdClass );609 $ blogs[ $blog_id ]->userblog_id = $blog_id;610 $ blogs[ $blog_id ]->blogname = get_option('blogname');611 $ blogs[ $blog_id ]->domain = '';612 $ blogs[ $blog_id ]->path = '';613 $ blogs[ $blog_id ]->site_id = 1;614 $ blogs[ $blog_id ]->siteurl = get_option('siteurl');615 $ blogs[ $blog_id ]->archived = 0;616 $ blogs[ $blog_id ]->spam = 0;617 $ blogs[ $blog_id ]->deleted = 0;618 return $ blogs;609 $site_id = get_current_blog_id(); 610 $sites = array( $site_id => new stdClass ); 611 $sites[ $site_id ]->userblog_id = $site_id; 612 $sites[ $site_id ]->blogname = get_option('blogname'); 613 $sites[ $site_id ]->domain = ''; 614 $sites[ $site_id ]->path = ''; 615 $sites[ $site_id ]->site_id = 1; 616 $sites[ $site_id ]->siteurl = get_option('siteurl'); 617 $sites[ $site_id ]->archived = 0; 618 $sites[ $site_id ]->spam = 0; 619 $sites[ $site_id ]->deleted = 0; 620 return $sites; 619 621 } 620 622 621 $ blogs = array();623 $site_ids = array(); 622 624 623 625 if ( isset( $keys[ $wpdb->base_prefix . 'capabilities' ] ) && defined( 'MULTISITE' ) ) { 624 $blog = get_blog_details( 1 ); 625 if ( $blog && isset( $blog->domain ) && ( $all || ( ! $blog->archived && ! $blog->spam && ! $blog->deleted ) ) ) { 626 $blogs[ 1 ] = (object) array( 627 'userblog_id' => 1, 628 'blogname' => $blog->blogname, 629 'domain' => $blog->domain, 630 'path' => $blog->path, 631 'site_id' => $blog->site_id, 632 'siteurl' => $blog->siteurl, 633 'archived' => $blog->archived, 634 'mature' => $blog->mature, 635 'spam' => $blog->spam, 636 'deleted' => $blog->deleted, 637 ); 638 } 626 $site_ids[] = 1; 639 627 unset( $keys[ $wpdb->base_prefix . 'capabilities' ] ); 640 628 } 641 629 … … 646 634 continue; 647 635 if ( $wpdb->base_prefix && 0 !== strpos( $key, $wpdb->base_prefix ) ) 648 636 continue; 649 $ blog_id = str_replace( array( $wpdb->base_prefix, '_capabilities' ), '', $key );650 if ( ! is_numeric( $ blog_id ) )637 $site_id = str_replace( array( $wpdb->base_prefix, '_capabilities' ), '', $key ); 638 if ( ! is_numeric( $site_id ) ) 651 639 continue; 652 640 653 $blog_id = (int) $blog_id; 654 $blog = get_blog_details( $blog_id ); 655 if ( $blog && isset( $blog->domain ) && ( $all || ( ! $blog->archived && ! $blog->spam && ! $blog->deleted ) ) ) { 656 $blogs[ $blog_id ] = (object) array( 657 'userblog_id' => $blog_id, 658 'blogname' => $blog->blogname, 659 'domain' => $blog->domain, 660 'path' => $blog->path, 661 'site_id' => $blog->site_id, 662 'siteurl' => $blog->siteurl, 663 'archived' => $blog->archived, 664 'mature' => $blog->mature, 665 'spam' => $blog->spam, 666 'deleted' => $blog->deleted, 667 ); 668 } 641 $site_ids[] = (int) $site_id; 642 } 643 644 $args = array( 645 'number' => '', 646 'site__in' => $site_ids, 647 ); 648 if ( ! $all ) { 649 $args['archived'] = 0; 650 $args['spam'] = 0; 651 $args['deleted'] = 0; 652 } 653 654 $_sites = get_sites( $args ); 655 656 $sites = array(); 657 foreach ( $_sites as $site ) { 658 $sites[ $site->id ] = (object) array( 659 'userblog_id' => $site->id, 660 'blogname' => $site->blogname, 661 'domain' => $site->domain, 662 'path' => $site->path, 663 'site_id' => $site->network_id, 664 'siteurl' => $site->siteurl, 665 'archived' => $site->archived, 666 'mature' => $site->mature, 667 'spam' => $site->spam, 668 'deleted' => $site->deleted, 669 ); 669 670 } 670 671 671 672 /** 672 * Filters the list of blogs a user belongs to.673 * Filters the list of sites a user belongs to. 673 674 * 674 675 * @since MU 675 676 * 676 * @param array $ blogs An array of blogobjects belonging to the user.677 * @param array $sites An array of site objects belonging to the user. 677 678 * @param int $user_id User ID. 678 * @param bool $all Whether the returned blogs array should contain all blogs, including679 * @param bool $all Whether the returned sites array should contain all sites, including 679 680 * those marked 'deleted', 'archived', or 'spam'. Default false. 680 681 */ 681 return apply_filters( 'get_blogs_of_user', $ blogs, $user_id, $all );682 return apply_filters( 'get_blogs_of_user', $sites, $user_id, $all ); 682 683 } 683 684 684 685 /**