Skip to content

Commit

Permalink
Allow get_user_role_from_sso to be filtered in multisite mode
Browse files Browse the repository at this point in the history
Fixes #95
  • Loading branch information
roborourke authored Jan 15, 2025
1 parent 8f71fa2 commit fe48e78
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions inc/namespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -798,27 +798,21 @@ function get_user_roles_from_sso( \WP_User $user, array $attributes ) {
$roles = (array) apply_filters( 'wpsimplesaml_map_role', get_option( 'default_role' ), $attributes, $user->ID, $user );
$roles = array_unique( array_filter( $roles ) );

if ( empty( $roles ) ) {
return [];
}

if ( is_sso_enabled_network_wide() ) {
$network_roles = [];

// 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

Check failure on line 803 in inc/namespace.php

View check run for this annotation

HM Linter / hmlinter

inc/namespace.php#L803

Inline comments must end in full-stops, exclamation marks, or question marks
Raw output
{
  "line": 803,
  "column": 9,
  "severity": "error",
  "message": "Inline comments must end in full-stops, exclamation marks, or question marks",
  "source": "Squiz.Commenting.InlineComment.InvalidEndChar"
}
if ( is_numeric( key( $roles ) ) ) { // Not an associative array ?
if ( is_array( current( $roles ) ) ) {
// Nested array? then it is a `sites` definition, expect array of roles for each site

Check failure on line 806 in inc/namespace.php

View check run for this annotation

HM Linter / hmlinter

inc/namespace.php#L806

Inline comments must end in full-stops, exclamation marks, or question marks
Raw output
{
  "line": 806,
  "column": 17,
  "severity": "error",
  "message": "Inline comments must end in full-stops, exclamation marks, or question marks",
  "source": "Squiz.Commenting.InlineComment.InvalidEndChar"
}
$network_roles['sites'] = $roles;
$roles = [ 'sites' => $roles ];
} else {
// Flat array of strings ? then expect it is roles to apply on all sites

Check failure on line 809 in inc/namespace.php

View check run for this annotation

HM Linter / hmlinter

inc/namespace.php#L809

Inline comments must end in full-stops, exclamation marks, or question marks
Raw output
{
  "line": 809,
  "column": 17,
  "severity": "error",
  "message": "Inline comments must end in full-stops, exclamation marks, or question marks",
  "source": "Squiz.Commenting.InlineComment.InvalidEndChar"
}
$network_roles['network'] = $roles;
$roles = [ 'network' => $roles ];
}
} elseif ( ! isset( $roles['network'] ) && ! isset( $roles['sites'] ) ) { // Associative but no 'network' or 'sites' keys ?
$network_roles = [];
$roles = [];
}
}

return $network_roles ?? (array) $roles;
return $roles;
}

0 comments on commit fe48e78

Please sign in to comment.