Hello
After checking multiple solutions from FAQ section I think that I found solve my problem:
This code based on email field from external database. I use this email to found user in WordPress database and get his roles.
If you don’t have email field in your external database you can use other field with which you can find the user (e.g. username).
More about searching user: https://developer.wordpress.org/reference/functions/get_user_by/
If script found the user I get his current roles and return this variable. If roles is empty I set up default role which is ‘subscriber’.
functions.php
//
// Set permission from WordPress admin panel
//
function set_wp_permission($roles, $username, $userData) {
$user_email = $userData['raw_response']['email'];
$user_wp_data = get_user_by('email', $user_email);
$user_roles = $user_wp_data->roles;
if( empty($user_roles) ){
$user_roles = array('subscriber');
}
return $user_roles;
}
add_filter('exlog_hook_filter_assign_roles', 'set_wp_permission', 10, 3);
I hope that helps 🙂
-
This reply was modified 1 year, 10 months ago by
mativve.