admin管理员组文章数量:1130349
So far I've only found plugins that are either obsolete or only affect which categories are displayed.
EDIT: The result should be that users can only select certain categories when they publish their post.
So far I've only found plugins that are either obsolete or only affect which categories are displayed.
EDIT: The result should be that users can only select certain categories when they publish their post.
Share Improve this question edited Dec 15, 2018 at 19:29 Malory asked Dec 15, 2018 at 18:54 MaloryMalory 11 bronze badge1 Answer
Reset to default 0Try using these codes:
function themename_check_user_role( $role, $user_id = null ) {
if ( is_numeric( $user_id ) )
$user = get_userdata( $user_id );
else
$user = wp_get_current_user();
if ( empty( $user ) )
return false;
return in_array( $role, (array) $user->roles );
}
// example use for the current user
if ( themename_check_user_role( 'customer' )
_e( "You've got access!", 'themename' );
else
_e( "Sorry, you don't have access!", 'themename' );
Here, you are checking whether a particular user has a role or not. If a match is found, true will be returned.
So far I've only found plugins that are either obsolete or only affect which categories are displayed.
EDIT: The result should be that users can only select certain categories when they publish their post.
So far I've only found plugins that are either obsolete or only affect which categories are displayed.
EDIT: The result should be that users can only select certain categories when they publish their post.
Share Improve this question edited Dec 15, 2018 at 19:29 Malory asked Dec 15, 2018 at 18:54 MaloryMalory 11 bronze badge1 Answer
Reset to default 0Try using these codes:
function themename_check_user_role( $role, $user_id = null ) {
if ( is_numeric( $user_id ) )
$user = get_userdata( $user_id );
else
$user = wp_get_current_user();
if ( empty( $user ) )
return false;
return in_array( $role, (array) $user->roles );
}
// example use for the current user
if ( themename_check_user_role( 'customer' )
_e( "You've got access!", 'themename' );
else
_e( "Sorry, you don't have access!", 'themename' );
Here, you are checking whether a particular user has a role or not. If a match is found, true will be returned.
本文标签: How can I restrict the categories users can post inbased on user roles
版权声明:本文标题:How can I restrict the categories users can post in, based on user roles? 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749095601a2315204.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论