WordPress has "Subscriber", "Contributor", "Author", "Editor" and "Management" by default There are five user roles "member", with permissions from low to high, but the default five roles may not be enough for us. In this case, you can use the add_role() function to create a role.
Usage
add_role( $role, $display_name, $capabilities );
Parameters
$role
(String) (required) User role ID
Default value: None
$display_name
(String) (required) The name of the user role displayed in the foreground
Default value: None
$capabilities
(array) (optional) Permissions of user role
Default value: None
Return value
If the role with this role ID does not exist and is successfully created, the WP_Role class is returned; if the user role already exists or the creation fails, null is returned.
Example
$result = add_role( 'new_role_created', __( '新建用户角色例子', 'Bing' ), array( 'read' => true, 'edit_posts' => true, 'delete_posts' => false ) ); if( $result ) echo '用户角色创建成功!'; else echo '因为用户角色已经存在或者其它原因导致创建失败!';
Others
This function is located at: wp-includes/capabilities.php
Although the WordPress user system looks very simple, it is very scalable. If you make good use of plug-ins, you can make the WordPress user system no worse than a professional forum system.
User permission management is a very important part of the user system. Although the permissions of these identities are very scientifically designed, they still cannot meet everyone's needs. This article will teach you how to customize the permissions of these identities. .
First install and enable the Capability Manager Enhanced plug-in, and go to "User" → "Capabilities" for permission management.
First select an identity whose permissions you want to edit in “Select New Role” on the right, and then adjust the permissions on the left.
Save it after making adjustments.