Created
May 19, 2016 17:45
-
-
Save Idealien/fefbf9509b6a00946ed0322c85a02fec to your computer and use it in GitHub Desktop.
WP All Import - Users - Maintain multiple roles in wp_capabilities user meta
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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