Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
WP All Import - Users - Maintain multiple roles in wp_capabilities user meta
<?php
function ipost_import_roles($employee_ID) {
$user_query = new WP_User_Query( array( 'meta_key' => 'employee_id', 'meta_value' => $employee_ID ) );
$defaultRole = array("employee" => true);
if ( ! empty( $user_query->results ) ) {
foreach ( $user_query->results as $user ) {
if( $user->roles ) {
$roles = $defaultRole;
foreach( $user->roles as $role ) {
$roles[$role] = true;
}
} else {
$roles = $defaultRole;
}
}
} else {
$roles = $defaultRole;
}
return serialize($roles);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.