add_role(등급 슬러그이름, 보여지는이름, 권한);새로운 유저의 등급(role)을 생성합니다.
function xx__update_custom_roles() {
if ( get_option( 'custom_roles_version' ) < 1 ) {
add_role( 'custom_role', 'Custom Subscriber', array( 'read' => true, 'level_0' => true ) );
update_option( 'custom_roles_version', 1 );
}
}
add_action( 'init', 'xx__update_custom_roles' );이 함수는 유저의 데이터에 귀속되기 때문에 여러번 불러들일 필요가 없습니다. 플러그인을 활성화하거나, 조건부 상황에서만 사용해야 합니다.
$result = add_role(
'guest_author',
__( 'Guest Author', 'testdomain' ),
array(
'read' => true, // true allows this capability
'edit_posts' => true,
'delete_posts' => false, // Use false to explicitly deny
)
);가장 정석의 코드입니다. 게스트를 생성할 수 있습니다.
add_role( 'superintendent', 'Superintendent', get_role( 'administrator' )->capabilities );기존 사용자의 역할을 복제하여 새 사용자 역할을 만들 수도 있습니다.
function add_roles_on_plugin_activation() {
add_role( 'custom_role', 'Custom Subscriber', array( 'read' => true, 'level_0' => true ) );
}
register_activation_hook( __FILE__, 'add_roles_on_plugin_activation' );플러그인이 활성화되었을 때 새로운 등급을 만들 수 있습니다. register_activation_hook 참조