Home >Backend Development >PHP Tutorial >Detailed explanation of the use of PHP functions related to creating user roles in WordPress, _PHP tutorial

Detailed explanation of the use of PHP functions related to creating user roles in WordPress, _PHP tutorial

WBOY
WBOYOriginal
2016-07-12 09:02:49888browse

Detailed explanation of the use of PHP functions related to creating user roles in WordPress,

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.

20151225152601421.png (1141×573)

Save it after making adjustments.

Articles you may be interested in:

  • WordPress code to determine whether the user is logged in
  • Detailed explanation of the function of reminding to install plug-ins and hiding plug-ins in WordPress
  • Sharing code examples for adding prompt boxes to the WordPress editing background
  • Detailed explanation of filtering properties and function usage of Sql statements in WordPress development
  • Related PHP function analysis for writing custom storage fields in WordPress

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1084523.htmlTechArticleDetailed explanation of the use of PHP functions related to creating user roles in WordPress. WordPress has "subscribers" and "contributors" by default , "Author", "Editor" and "Administrator" five user corners...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn