插件开发文档

💡 云策文档标注

概述

本文档介绍了WordPress中的用户概念,包括用户账户的基本属性和存储方式。重点阐述了用户角色与权限机制,以及如何遵循最小权限原则进行开发。

关键要点

  • 用户是WordPress中的访问账户,至少包含用户名、密码和电子邮件地址,存储在users表中。
  • 用户被分配角色,每个角色具有一组权限(capabilities),开发者可创建自定义角色和权限。
  • WordPress遵循最小权限原则,建议开发者创建适当角色并在执行敏感任务前检查权限。

📄 原文内容

A User is an access account with corresponding capabilities within the WordPress installation. Each WordPress user has, at the bare minimum, a username, password and email address.

Once a user account is created, that user may log in using the WordPress Admin (or programmatically) to access WordPress functions and data. WordPress stores the Users in the users table.

Roles and Capabilities

Users are assigned roles, and each role has a set of capabilities.

You can create new roles with their own set of capabilities. Custom capabilities can also be created and assigned to existing roles or new roles.

In WordPress, developers can take advantage of user roles to limit the set of actions an account can perform.

The Principle of Least Privileges

WordPress adheres to the principal of least privileges, the practice of giving a user only the privileges that are essential for performing the desired work. You should follow this lead when possible by creating roles where appropriate and checking capabilities before performing sensitive tasks.