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

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

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用户角色名称及权限的方法。

推荐阅读:
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 
评论列表
添加评论