Create a gist now

Instantly share code, notes, and snippets.

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