PHP functions related to creating user roles in WordPress _ php tips-php Tutorial

Source: Internet
Author: User
This article describes how to use functions related to user role creation in WordPress. in the WordPress multi-user mode, different roles have different permissions, for more information, see WordPress. WordPress has five user roles by default: "subscriber", "contributor", "author", "edit", and "administrator, however, the default five roles may not be enough for use. 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) name of the user role displayed on the foreground

Default value: None

$ Capabilities

(Array) (optional) user role permissions

Default value: None

Return value

If the role ID does not exist and is created successfully, the WP_Role class is returned. if the role already exists or fails to be created, the system returns null.

Example

$ Result = add_role ('New _ role_created ', _ ('example of creating a user role', 'Bing '), array ('read' => true, 'edit _ posts' => true, 'delete _ posts' => false); if ($ result) echo 'user role created successfully! '; Else echo' creation failed because the user role already exists or for other reasons! ';

Others

This function is located in: wp-nodes des/capabilities. php

Although the WordPress user system looks very simple, it has a very strong scalability. using the plug-in, we can make WordPress user systems worse than professional Forum Systems.

User permission management is an important part of the user system. Although the permission design for these identities is very scientific, it still cannot meet the needs of everyone, 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.

Select New Role on the right, Select an identity for editing permissions, and then adjust permissions on the left.

Save the changes.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.