如何添加和删除wordpress用户角色

  • 时间:2020-05-20 15:19:20
  • 分类:网络文摘
  • 阅读:90 次

wordpress默认有五种用户角色,按权限从低到高排列分别为:订阅者(subscriber)、投稿者(contributor )、作者(author)、编辑(editor )、管理员(administrator ),如果你的wordpress开放了注册,而默认的角色名称无法满足你的需要,可以使用下面介绍的wordpress技巧添加或删除角色。

一、添加新角色,并为其赋予分类管理、多媒体文件上传、文章编辑等基本权限。

如何添加或删除wordpress用户角色

复制如下代码到wordpress主题的functions.php文件中:

  1. function tp_add_role() {
  2.     add_role( 'newbie', '新角色',
  3.              array(
  4.                   'read',
  5.                   'edit_posts',
  6.                   'delete_posts',
  7.                   'manage_categories',
  8.                   'upload_files',
  9.                   )
  10.     );
  11. }
  12. add_action( 'init', 'tp_add_role' );

替换其中的“新角色”为你想要的角色名称。

二、删除订阅者、投稿者、作者、编辑等不需要的默认角色。

复制如下代码到wordpress主题的functions.php文件中:

  1. function wps_remove_role() {
  2.     remove_role( 'contributor' );
  3.     remove_role( 'subscriber' );
  4.     remove_role( 'author' );
  5.     remove_role( 'editor' );
  6. }
  7. add_action( 'init', 'wps_remove_role' );

代码中2至5行为想要删除的默认角色,依次为订阅者、投稿者、作者、编辑,可根据需要删减之。

注:以上两段代码使用后即可删除,无需留在functions.php文件中。

如果你还想要进一步了解wordpress默认角色,修改其原有名称或更改角色权限,可以参考:修改wordpress用户角色名称及权限的方法。

推荐阅读:
Emerging Social Media Tools for Bloggers 2017  The Current State of Content Marketing [Infographic]  How Facebook Can Build Or Destroy An Entrepreneur’s Career  Top 3 Email Marketing Software for Turning Subscribers Into Cust  Five Reasons to Get Business Funding for Your Blog  How to Compute the Surface Area of 3D Shapes (Cubes Placed on Gr  How to Find the Longest Harmonious Subsequence?  How to Find the Length of Longest Fibonacci Subsequence using Br  How to Find the Length of the Longest Increasing Subsequence usi  Facing Heads Probabilties of Tossing Strange Coins using Dynamic 
评论列表
添加评论