Skip to content

Commit

Permalink
For non-super-admins, use get_blogs_of_user() to determine authroized…
Browse files Browse the repository at this point in the history
… sites.
  • Loading branch information
peterwilsoncc committed Jan 14, 2024
1 parent 14b56e6 commit 81604ed
Showing 1 changed file with 31 additions and 6 deletions.
37 changes: 31 additions & 6 deletions includes/classes/InternalConnections/NetworkSiteConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -866,12 +866,37 @@ public static function build_available_authorized_sites( $user_id = false, $cont

if ( $force || false === $authorized_sites ) {
$authorized_sites = array();
$sites = get_sites(
array(
'number' => 1000,
)
);
$current_blog_id = (int) get_current_blog_id();

if ( is_super_admin() ) {
$sites = get_sites(
array(
'number' => 1000,
)
);
} else {
$user_sites = get_blogs_of_user( $user_id );
$user_site_ids = wp_list_pluck( $user_sites, 'userblog_id' );
$sites = array();

/*
* get_blogs_of_user() returns sites in a different shape to get_sites().
*
* This gets each of the sites in the correct shape, get_site() is called for each
* site individually as the sites will each be cached so this is more performant
* than using get_sites().
*/
foreach ( $user_site_ids as $user_site_id ) {
$user_site = get_site( $user_site_id );

if ( ! $user_site ) {
continue;
}

$sites[] = $user_site;
}
}

$current_blog_id = (int) get_current_blog_id();

foreach ( $sites as $site ) {
$blog_id = (int) $site->blog_id;
Expand Down

0 comments on commit 81604ed

Please sign in to comment.