Changeset 38682
- Timestamp:
- 09/30/2016 04:34:18 AM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/user.php
r38651 r38682 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 * @since 4.7.0 Converted to use get_sites(). 565 566 * 566 567 * @global wpdb $wpdb WordPress database abstraction object. 567 568 * 568 569 * @param int $user_id User ID 569 * @param bool $all Whether to retrieve all blogs, or only blogs that are not570 * @param bool $all Whether to retrieve all sites, or only sites that are not 570 571 * 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.572 * @return array A list of the user's sites. An empty array if the user doesn't exist 573 * or belongs to no sites. 573 574 */ 574 575 function get_blogs_of_user( $user_id, $all = false ) { … … 577 578 $user_id = (int) $user_id; 578 579 579 // Logged out users can't have blogs580 // Logged out users can't have sites 580 581 if ( empty( $user_id ) ) 581 582 return array(); … … 589 590 * @since 4.6.0 590 591 * 591 * @param null|array $ blogs An array of WP_Site objects of which the user is a member.592 * @param null|array $sites An array of site objects of which the user is a member. 592 593 * @param int $user_id User ID. 593 594 * @param bool $all Whether the returned array should contain all sites, including 594 595 * those marked 'deleted', 'archived', or 'spam'. Default false. 595 596 */ 596 $ blogs = apply_filters( 'pre_get_blogs_of_user', null, $user_id, $all );597 598 if ( null !== $ blogs ) {599 return $ blogs;597 $sites = apply_filters( 'pre_get_blogs_of_user', null, $user_id, $all ); 598 599 if ( null !== $sites ) { 600 return $sites; 600 601 } 601 602 … … 605 606 606 607 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;619 } 620 621 $ blogs = array();608 $site_id = get_current_blog_id(); 609 $sites = array( $site_id => new stdClass ); 610 $sites[ $site_id ]->userblog_id = $site_id; 611 $sites[ $site_id ]->blogname = get_option('blogname'); 612 $sites[ $site_id ]->domain = ''; 613 $sites[ $site_id ]->path = ''; 614 $sites[ $site_id ]->site_id = 1; 615 $sites[ $site_id ]->siteurl = get_option('siteurl'); 616 $sites[ $site_id ]->archived = 0; 617 $sites[ $site_id ]->spam = 0; 618 $sites[ $site_id ]->deleted = 0; 619 return $sites; 620 } 621 622 $site_ids = array(); 622 623 623 624 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 } 625 $site_ids[] = 1; 639 626 unset( $keys[ $wpdb->base_prefix . 'capabilities' ] ); 640 627 } … … 647 634 if ( $wpdb->base_prefix && 0 !== strpos( $key, $wpdb->base_prefix ) ) 648 635 continue; 649 $ blog_id = str_replace( array( $wpdb->base_prefix, '_capabilities' ), '', $key );650 if ( ! is_numeric( $ blog_id ) )636 $site_id = str_replace( array( $wpdb->base_prefix, '_capabilities' ), '', $key ); 637 if ( ! is_numeric( $site_id ) ) 651 638 continue; 652 639 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, 640 $site_ids[] = (int) $site_id; 641 } 642 643 $sites = array(); 644 645 if ( ! empty( $site_ids ) ) { 646 $args = array( 647 'number' => '', 648 'site__in' => $site_ids, 649 ); 650 if ( ! $all ) { 651 $args['archived'] = 0; 652 $args['spam'] = 0; 653 $args['deleted'] = 0; 654 } 655 656 $_sites = get_sites( $args ); 657 658 foreach ( $_sites as $site ) { 659 $sites[ $site->id ] = (object) array( 660 'userblog_id' => $site->id, 661 'blogname' => $site->blogname, 662 'domain' => $site->domain, 663 'path' => $site->path, 664 'site_id' => $site->network_id, 665 'siteurl' => $site->siteurl, 666 'archived' => $site->archived, 667 'mature' => $site->mature, 668 'spam' => $site->spam, 669 'deleted' => $site->deleted, 667 670 ); 668 671 } … … 670 673 671 674 /** 672 * Filters the list of blogs a user belongs to.675 * Filters the list of sites a user belongs to. 673 676 * 674 677 * @since MU 675 678 * 676 * @param array $ blogs An array of blogobjects belonging to the user.679 * @param array $sites An array of site objects belonging to the user. 677 680 * @param int $user_id User ID. 678 * @param bool $all Whether the returned blogs array should contain all blogs, including681 * @param bool $all Whether the returned sites array should contain all sites, including 679 682 * those marked 'deleted', 'archived', or 'spam'. Default false. 680 683 */ 681 return apply_filters( 'get_blogs_of_user', $ blogs, $user_id, $all );684 return apply_filters( 'get_blogs_of_user', $sites, $user_id, $all ); 682 685 } 683 686
Note: See TracChangeset
for help on using the changeset viewer.