From e8631676d3364bd34993e429717273a1b9424a94 Mon Sep 17 00:00:00 2001 From: Chad <867697+chadsterBAM@users.noreply.github.com> Date: Mon, 5 Nov 2018 12:00:29 -0500 Subject: [PATCH 1/4] Fixed for associative array of roles --- inc/namespace.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/inc/namespace.php b/inc/namespace.php index 43f9a90..a3ea52a 100644 --- a/inc/namespace.php +++ b/inc/namespace.php @@ -469,7 +469,8 @@ function map_user_roles( $user, array $attributes ) { // Manage super admin flag if ( is_sso_enabled_network_wide() ) { if ( isset( $roles['network'] ) && in_array( 'superadmin', $roles['network'], true ) ) { - $roles = array_diff( $roles['network'], [ 'superadmin' ] ); + // $roles = array_diff( $roles['network'], [ 'superadmin' ] ); + // Had to remove this line. It removes the $roles['sites'] from the array. Cant have that as we have Super Admins who are also specific roles in specific sites. if ( ! is_super_admin( $user->ID ) ) { grant_super_admin( $user->ID ); @@ -496,8 +497,15 @@ function map_user_roles( $user, array $attributes ) { $user->for_site( $site_id ); $user->set_role( reset( $site_roles ) ); - foreach ( array_slice( $site_roles, 1 ) as $role ) { - $user->add_role( $role ); + foreach ( $site_roles as $role ) { + // modified to include multiple roles per site. Our sites included multiple roles in an associative array. + if (is_array($role)) { + foreach ($role as $r) { + $user->add_role($r); + } + } else { + $user->add_role( $role ); + } } } } elseif ( ! isset( $roles['sites'] ) && isset( $roles['network'] ) ) { From 48b4b3bbe48d64caffbce108b4333ed957dd2079 Mon Sep 17 00:00:00 2001 From: Chad <867697+chadsterBAM@users.noreply.github.com> Date: Mon, 5 Nov 2018 12:13:29 -0500 Subject: [PATCH 2/4] Fixed blank array for $network_roles If both $roles['sites'] and $roles['network'] are being used, thekey $network_roles stays blank and the update fails to add roles. --- inc/namespace.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/inc/namespace.php b/inc/namespace.php index a3ea52a..a858a64 100644 --- a/inc/namespace.php +++ b/inc/namespace.php @@ -729,7 +729,8 @@ function get_user_roles_from_sso( \WP_User $user, array $attributes ) { } if ( is_sso_enabled_network_wide() ) { - $network_roles = []; + // $network_roles = []; + // removed because it's not previously named and breaks if you have $roles['sites'] and $roles['network'] in the same array. Keys are not numeric. // If this is a multisite, the roles array may contain a 'network' key and a 'sites' key. Otherwise, if // it is a flat array, use it to add the roles for all sites From aeaaa5efcec9b47942f70037d202a6b440408090 Mon Sep 17 00:00:00 2001 From: Chad <867697+chadsterBAM@users.noreply.github.com> Date: Mon, 5 Nov 2018 13:15:16 -0500 Subject: [PATCH 3/4] Fixed spacing to pass travis --- inc/namespace.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/inc/namespace.php b/inc/namespace.php index a858a64..166ecb7 100644 --- a/inc/namespace.php +++ b/inc/namespace.php @@ -499,9 +499,9 @@ function map_user_roles( $user, array $attributes ) { foreach ( $site_roles as $role ) { // modified to include multiple roles per site. Our sites included multiple roles in an associative array. - if (is_array($role)) { - foreach ($role as $r) { - $user->add_role($r); + if ( is_array( $role ) ) { + foreach ( $role as $r ) { + $user->add_role( $r ); } } else { $user->add_role( $role ); From 35fafed260b4459ca58f5a76b9fffcf4a95a15c2 Mon Sep 17 00:00:00 2001 From: Chad <867697+chadsterBAM@users.noreply.github.com> Date: Wed, 21 Nov 2018 11:29:45 -0500 Subject: [PATCH 4/4] restore_current_blog() to force it back to the orginating blog. We found a bug that brought users to the last blog in their blogs list upon login instead of logging them into the blog they first visited. This code addition fixes that. --- inc/namespace.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/inc/namespace.php b/inc/namespace.php index 166ecb7..06b1f95 100644 --- a/inc/namespace.php +++ b/inc/namespace.php @@ -507,6 +507,8 @@ function map_user_roles( $user, array $attributes ) { $user->add_role( $role ); } } + // Switch back to original blog in the situation where the user has multiple blogs. + restore_current_blog(); } } elseif ( ! isset( $roles['sites'] ) && isset( $roles['network'] ) ) { $all_site_ids = new \WP_Site_Query( [