Post Views: 1,218
取目前使用者或指定使用者的角色名稱
<?php
/*
v123 DEV
https://v123.tw
Get user role names
@param int|string|stdClass|WP_User $id User's ID, a WP_User object, or a user object from the DB.
@return array
*/
function get_user_role_names( $user = null ) {
if(!function_exists('wp_get_current_user')) {
include( ABSPATH . "wp-includes/pluggable.php" );
}
$user = $user ? new WP_User( $user ) : wp_get_current_user();
if ( $user->exists() ) {
return $user->roles ? $user->roles : array();
}else{
return array();
}
}