如何添加和删除wordpress用户角色
- 时间:2020-05-20 15:19:20
- 分类:网络文摘
- 阅读:105 次
wordpress默认有五种用户角色,按权限从低到高排列分别为:订阅者(subscriber)、投稿者(contributor )、作者(author)、编辑(editor )、管理员(administrator ),如果你的wordpress开放了注册,而默认的角色名称无法满足你的需要,可以使用下面介绍的wordpress技巧添加或删除角色。
一、添加新角色,并为其赋予分类管理、多媒体文件上传、文章编辑等基本权限。
复制如下代码到wordpress主题的functions.php文件中:
- function tp_add_role() {
- add_role( 'newbie', '新角色',
- array(
- 'read',
- 'edit_posts',
- 'delete_posts',
- 'manage_categories',
- 'upload_files',
- )
- );
- }
- add_action( 'init', 'tp_add_role' );
替换其中的“新角色”为你想要的角色名称。
二、删除订阅者、投稿者、作者、编辑等不需要的默认角色。
复制如下代码到wordpress主题的functions.php文件中:
- function wps_remove_role() {
- remove_role( 'contributor' );
- remove_role( 'subscriber' );
- remove_role( 'author' );
- remove_role( 'editor' );
- }
- add_action( 'init', 'wps_remove_role' );
代码中2至5行为想要删除的默认角色,依次为订阅者、投稿者、作者、编辑,可根据需要删减之。
注:以上两段代码使用后即可删除,无需留在functions.php文件中。
如果你还想要进一步了解wordpress默认角色,修改其原有名称或更改角色权限,可以参考:修改wordpress用户角色名称及权限的方法。
推荐阅读:Coding For Profit: 4 Types Of Websites To Consider Building How to Compute the Projection Area of 3D Shapes? How To Find The Ideal Monitor For Coders? How to Partition an Array Into Three Parts With Equal Sum? Compute the Sum of Even Numbers After Queries How to Compute Nested List Weight Sum of Any Arrays? 7 Laws Every Blogger Must Know to Avoid Lawsuits New App Protects You From Becoming A Victim Of White Collar Crim Sprout Social Develops Bot Builder for Automated Conversational Which Analytics Stats Really Matter to Your Blog and Marketing C
- 评论列表
-
- 添加评论