wordpress角色能力

说到角色能力,我们先来说一个函数
current_user_can
看一下使用

current_user_can( $capability, $args );

args 参数是非必要的,是额外给予的参数,例如:current_user_can('edit_post', 121),意指给他可以编辑编号为121的文章。

角色判断

if( current_user_can('administrator') ) {
    echo '文字只有管理员才能看的到';
}

使用举例:

1 判断用户是否为管理员(administrator)

if ( current_user_can (  'manage_options'  )  )  {
    echo  'The current user is a administrator' ;
}

2 判断用户是否为编辑(Editor)

if ( current_user_can (  'publish_pages'  )  &&  ! current_user_can (  'manage_options'  )  )  {
    echo  'The current user is an editor' ;
}

3 判断用户是否为作者(Author)

if ( current_user_can (  'publish_posts'  )  &&  ! current_user_can (  'publish_pages'  )  )  {
    echo  'The current user is an author' ;
}

4 判断用户是否为投稿者(Contributor)

if ( current_user_can (  'edit_posts'  )  &&  ! current_user_can (  'publish_posts'  )  )  { 
    echo  'The current user is a contributor' ; 
}

5 判断用户是否为订阅者(Subscriber)

if ( current_user_can (  'read'  )  &&  ! current_user_can (  'edit_posts'  )  )  { 
    echo  'The current user is a subscriber' ; 
}

你可能感兴趣的:(wordpress角色能力)