如何添加和删除wordpress用户角色
- 时间:2020-05-20 15:19:20
- 分类:网络文摘
- 阅读:97 次
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用户角色名称及权限的方法。
推荐阅读:The Brace Expansion Algorithms using Breadth First Search or Dep Coding Exercise: Sum of Digits in the Minimum Number Javascript Coding Exercise: The QuickSort Implementation in Java In-place Run-Length String Compressions using C++ Algorithms to Compute the Factor Combinations for An Integer usi How and Why You Should Use Infographics On Your Blog How to Make Your “Contact Us” Page Kick Ass The A to Z of Content Marketing: Habits Every Content Marketer S Keeping the Flame Going: How to Rock a Steady Job and Still Have How to Use Social Media and User-Generated Content to Boost Traf
- 评论列表
-
- 添加评论