如何添加和删除wordpress用户角色
- 时间:2020-05-20 15:19:20
- 分类:网络文摘
- 阅读:86 次
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用户角色名称及权限的方法。
推荐阅读:How to Find the Dominant Index in Array (Largest Number At Least K Closest Points to Origin Algorithm by using Priority Queues in Total Number of Ways to Decode the Message via Dynamic Programmi The License Key Formatting Algorithm in C++ Integrating LinkedIn Long-Form Posts in Your Blogging Strategy A Quick Guide on Beefing Up Your WordPress Security 10 Proven Ways to Destroy Writer’s Block 3 Chrome Blogging Extensions to Watch Out for 2015 Cloud-Based Tools to Stake Your Business Blog On How To Protect Your Brand On Social Media
- 评论列表
-
- 添加评论