API / Minn\Rest / UsersController

UsersController final readonly class

Minn\Rest\UsersController · public/minn/src/Minn/Rest/UsersController.php · 379 lines

wp/v2 users: me, list, single, and the create/update/delete-with-reassign the Users view drives.

Used by 1

Constants and properties

privatereadonly Minn\Db $db

Promoted from the constructor.

privatereadonly Minn\Content\Users $users

Promoted from the constructor.

privatereadonly Minn\Content\Site $site

Promoted from the constructor.

privatereadonly Minn\Rest\UserObject $object

Promoted from the constructor.

privatereadonly Minn\Rest\RestUrl $url

Promoted from the constructor.

privatereadonly Minn\Rest\Caller $caller

Promoted from the constructor.

privatereadonly Minn\Auth\Roles $roles

Promoted from the constructor.

privatereadonly Minn\Rest\Schema $schema

Promoted from the constructor.

Public

new__construct(Minn\Db $db, Minn\Content\Users $users, Minn\Content\Site $site, Minn\Rest\UserObject $object, Minn\Rest\RestUrl $url, Minn\Rest\Caller $caller, Minn\Auth\Roles $roles, Minn\Rest\Schema $schema)#
methodme(Minn\Http\Request $request): Minn\Http\ResponseGET /wp/v2/users/me (public)#

The signed-in user.

methodupdateMe(Minn\Http\Request $request): Minn\Http\ResponsePOST /wp/v2/users/me (signed in)PUT /wp/v2/users/me (signed in)PATCH /wp/v2/users/me (signed in)#

Updates the signed-in user; signed out there is no such user (404), and the Allow header leaves the writes out.

methoddeleteMe(Minn\Http\Request $request): Minn\Http\ResponseDELETE /wp/v2/users/me (cap delete_users)#

Deletes the signed-in user as users/{id} deletes any; signed out there is no such user (404).

methodlist(Minn\Http\Request $request): Minn\Http\ResponseGET /wp/v2/users (public)#

The users list as the reference serves it: the request's WP_User_Query through rest_user_collection_params and rest_user_query (a reader who may not list users sees published authors only), its totals (counted again without the page when it found none), and the users it found.

methodsingle(Minn\Http\Request $request, string $id): Minn\Http\ResponseGET /wp/v2/users/{id:[\d]+} (public; user {id} must exist)#

One user.

methodcreate(Minn\Http\Request $request): Minn\Http\ResponsePOST /wp/v2/users (cap create_users)#

Engine-created users carry real scheme hashes and the full default meta set.

methodupdate(Minn\Http\Request $request, string $id): Minn\Http\ResponsePOST /wp/v2/users/{id:[\d]+} (cap edit_user on {id}; user {id} must exist)PUT /wp/v2/users/{id:[\d]+} (cap edit_user on {id}; user {id} must exist)PATCH /wp/v2/users/{id:[\d]+} (cap edit_user on {id}; user {id} must exist)#

Updates a user.

methoddelete(Minn\Http\Request $request, string $id): Minn\Http\ResponseDELETE /wp/v2/users/{id:[\d]+} (cap delete_users; user {id} must exist)#

reassign is REQUIRED (checked before the user lookup), and so is force.

Internals 8

Private and protected methods: how the class does its work. Not a contract; they change whenever the code is tidied.

privatelistAllowed(Minn\Objects\RestRequest $wp, Minn\Rest\Context $context): void#

What a reader who may not list users may not ask the list for: the edit context, an email or registration order, roles, capabilities; the authors shorthand is for those who may edit posts.

privatetotals(Minn\Objects\UsersQuery $query, array $args): array#

The total and the page count: the query's own, or, when it found none, a count without the page; pages by the query's own number.

$argsarray<string, mixed>
@return array{0: int, 1: int}
privatehasPublishedContent(int $userId): bool#
privatevalidRole(string $role): string#

A role must be registered, as the reference insists.

privatevalidLocale(array $body): void#

A locale asked for is one the site can show: none, en_US, or an installed language, as the reference's schema lists them (audit Low: any string was stored, and pasted into the reset link).

$bodyarray<string, mixed>
privateassignableRole(string $role): string#

A role asked for: registered, and one editable_roles lets this caller give (audit Low).

privatevalidEmail(string $email): bool#
privateloginRefusal(string $login): ?string#

Why a new login is refused, in the reference's words, or null: it must come through strict sanitizing unchanged (validate_username, with plugins loaded), and no illegal_user_logins entry may name it.