WordPress Create user Role related PHP functions using the detailed _php tips

Source: Internet
Author: User

WordPress defaults to "subscribers," "Contributors," "Author," "Edit," and "admin" five user roles, the permissions from low to high, but the default five roles may not be enough for us, then 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 for user roles

Default value: None

return value

If the role of this role ID does not exist and the creation succeeds, the Wp_role class is returned, the user role already exists, or the creation failure returns NULL.

Example

$result = Add_role (' new_role_created ', __ (' New User Role example ', ' Bing '), Array (
  ' read ' => true,
  ' edit_posts ' => tru E,
  ' delete_posts ' => false
));
if ($result) echo ' user role was created successfully! ';
else echo ' because the user role already exists or otherwise causes the creation to fail! ';

Other

This function is located at: wp-includes/capabilities.php

WordPress user system seems to be very simple, but the scalability is very strong, good use of plug-ins, you can make the user system WordPress is not more than the professional forum system.

User's rights management is a very important part of the user system, although these several identity authority design is very scientific, but still can not meet everyone's needs, this article will teach you how to customize these several identity permissions.
First installs and enables the Capability Manager enhanced plug-in, enters "the user" → "capabilities" carries on the Authority management.

First select an identity to edit permissions on the right side of select New role, and then adjust the permissions on the left.

After the adjustment, you can save.

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.