Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions src/authorizer/class-authorization.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,15 @@ public function check_user_access( $user, $user_emails, $user_data = array() ) {
* @param bool $role Role of the user currently logging in.
* @param array $user_data User data returned from external service.
*/
$approved_role = apply_filters( 'authorizer_custom_role', $default_role, $user_data );

$add_roles = [];
$remove_roles = [];
$custom_role_return = apply_filters( 'authorizer_custom_role', $default_role, $user_data );
if (is_array($custom_role_return) && count($custom_role_return, 0) == 3)
[$approved_role, $add_roles, $remove_roles] = $custom_role_return;
else
$approved_role = $custom_role_return;

/**
* Filter whether to automatically approve the currently logging in user
* based on any of their user attributes.
Expand Down Expand Up @@ -308,7 +315,9 @@ public function check_user_access( $user, $user_emails, $user_data = array() ) {
* );
*/
do_action( 'authorizer_user_register', $user, $user_data );

// Add Secondary roles to user
foreach($add_roles as $role)
$user->add_role($role);
// If multisite, iterate through all sites in the network and add the user
// currently logging in to any of them that have the user on the approved list.
// Note: this is useful for first-time logins--some users will have access
Expand Down Expand Up @@ -392,6 +401,13 @@ function ( $site_of_user ) {
if ( $should_update_last_name ) {
update_user_meta( $user->ID, 'last_name', $user_data['last_name'] );
}
// Update User Roles
foreach($add_roles as $role)
if(!in_array($role, $user->roles))
$user->add_role($role);
foreach($remove_roles as $role)
if(in_array($role, $user->roles))
$user->remove_role($role);
}

// If this is multisite, add new user to current blog.
Expand Down