有可能做到这一点吗?我已经知道get current\\u user\\u can(),但它的工作方式与我需要的不同。如果有多个角色,我希望能够使用数组。
// Check roles to only add fields to necessary users
function check_role( $user ) {
$user_role = get_user_role($user->ID);
if($user_role == \'author\') {
return true;
} else {
return false;
}
}
add_action(\'show_user_profile\', \'check_role\');
add_action(\'edit_user_profile\', \'check_role\');
if(check_role()) {
add_action(\'show_user_profile\', \'add_user_fields\');
add_action(\'edit_user_profile\', \'add_user_fields\');
add_action( \'personal_options_update\', \'save_user_fields\' );
add_action( \'edit_user_profile_update\', \'save_user_fields\' );
}