current_user_can() | 유저 액세스 여부

|

설명

current_user_can()

현재 접속한 사용자에게 지정한 권한이 있는지 여부를 반환합니다.

사용법

current_user_can( 'edit_posts' );
current_user_can( 'edit_post', $post->ID );
current_user_can( 'edit_post_meta', $post->ID, $meta_key );

해당 글에 대한 수정 권한이 있는지를 체크합니다.

current_user_can( 'administrator' );

유저가 해당 역할을 할 수 있는지 체크합니다. 다른 매개변수는 administrator(관리자), editor(에디터), author(작성자), contributor(기여자), subcriber(구독자) 가 있습니다.

if 문과 함께쓰기

if( current_user_can( 'edit_post', $post->ID ) ){

// 수정 권한 여부
}

현재 로그인한 유저가 현재 글($post->ID)에 수정 권한을 가지고 있으면 조건문을 실행합니다.

if( current_user_can( 'administrator' ) ){
// 관리자 권한 여부
}

현재 로그인한 유저가 관리자 권한을 가지고 있으면 조건문을 실행합니다.

참조

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다

클릭하여 복사