반응형
WordPress에서 현재 사용자의 역할을 아는 방법
사용자가 새 게시물을 작성할 때 현재 역할을 확인하려면 어떻게 해야 합니까?
워드프레스의 후크가 뭔지 알고 있을 겁니다이 부분을 건너뛰면 사용자의 현재 역할을 쉽게 파악할 수 있습니다.
$current_user = wp_get_current_user();
if ( !($current_user instanceof WP_User) )
return;
$roles = $current_user->roles; //$roles is an array
이제 해당 어레이를 반복하여 사용자에게 특정 역할이 있는지 확인할 수 있습니다.
또는 를 사용할 수 있습니다.current_user_can
사용자가 특정 권한을 가지고 있는지 여부와 역할에 속해 있는지 여부를 확인하는 경우.예를 들어 다음과 같습니다.
if (current_user_can('delete_posts')) {
//display the delete posts button.
}
이 코드가 도움이 됩니다.
<?php echo array_shift(wp_get_current_user()->roles); ?>
언급URL : https://stackoverflow.com/questions/3499104/how-to-know-the-role-of-current-user-in-wordpress
반응형
'programing' 카테고리의 다른 글
Play 2.2 라이브러리로 밀봉된 특성을 위한 노이즈 프리 JSON 형식 (0) | 2023.02.26 |
---|---|
Python: 간단한 설정/구성 파일을 저장하는 방법은 무엇입니까? (0) | 2023.02.26 |
jQuery ajax 호출에 여러 파라미터 전달 (0) | 2023.02.26 |
jq: 문자열로 어레이를 인덱싱할 수 없습니다. (0) | 2023.02.26 |
$sce.trustAsResourceUrl() 글로벌 (0) | 2023.02.21 |