Repository navigation
Abilities API: Add the core/user-create, core/user-update and core/user-delete abilities - #16074
jorgefilipecosta wants to merge 2 commits into
Conversation
…re/user-delete` abilities. Add three abilities to the `user` category: - `core/user-create` creates a user from `data` and returns it. The password is generated and never returned: the new user receives the email with the link to set one. - `core/user-update` updates the given attributes of the user matched by `where` and returns it. - `core/user-delete` deletes the user matched by `where`, or on multisite removes the user from the current site. `reassign` is required: the ID of the user who takes over the content, or false. The attributes that can be written are the email, name, first name, last name, nickname, slug, description, URL, locale and roles, plus the username on create. Each call checks the capabilities of the current user for the target user and for the roles it sets. The `fields` and item schemas of `core/users-query` move to private helpers that the new abilities share. That ability is registered as before.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
Replace the `@ticket` placeholder in the tests of `core/user-create`, `core/user-update` and `core/user-delete` with 66720. See #66720.
Follow-up to #10775, with the shape from WordPress/abilities#22.
This PR adds the
core/user-create,core/user-updateandcore/user-deleteabilities to theusercategory:core/user-createtakes{ data, fields }and returns the new user.data.usernameanddata.emailare required. The password is generated and never returned: the new user gets the email with the link to set one.core/user-updatetakes{ where: { id }, data, fields }, changes only the attributes indataand returns the user.core/user-deletetakes{ where: { id }, reassign }and returns{ outcome }:deleted, orremovedon multisite, where the user leaves the current site and the account stays in the network.reassignis required: the ID of the user who takes over the content, orfalse.dataacceptsemail,name,first_name,last_name,nickname,slug,description,url,localeandroles, plususernameon create.create_users, update a logged-in user and deletedelete_users(remove_userson multisite). Each call then checks the capabilities of the user for the target user and for the roles it sets.core/users-queryitem, with the samefieldsand the same checks per field.core/users-queryis registered as before: itsfieldsand item schemas moved to private helpers that the new abilities share. In its tests, the helper that registers it now unregisters the four user abilities, and the run route tests get the cases of the three new abilities.Creating a user:
{ "id": 2, "name": "Ana Silva", "link": "http://example.org/author/anasilva/", "slug": "anasilva", "avatar_urls": { "24": "https://secure.gravatar.com/avatar/86b9260a115ceac89a9738af23696ce3a5d70449de8d95ef28bd754bb80196b9?s=24&d=mm&r=g", "48": "https://secure.gravatar.com/avatar/86b9260a115ceac89a9738af23696ce3a5d70449de8d95ef28bd754bb80196b9?s=48&d=mm&r=g", "96": "https://secure.gravatar.com/avatar/86b9260a115ceac89a9738af23696ce3a5d70449de8d95ef28bd754bb80196b9?s=96&d=mm&r=g" } }Changing the role and the description, and asking for some fields:
{ "id": 2, "name": "Ana Silva", "description": "Writes the release notes.", "email": "ana@example.org", "roles": [ "editor" ] }Deleting the user and giving their content to user 1 (use the ID of a user of your site). With
reassign: falsethe content is deleted with the user:{ "outcome": "deleted" }Trac ticket: https://core.trac.wordpress.org/ticket/66720
Testing
Verify unit tests are passing:
Or run the examples above in the editor console as an administrator.
AI disclosure: the change and tests were drafted with AI assistance (Claude Code).