API / Minn\Runtime / UserEvents

UserEvents final readonly class

Minn\Runtime\UserEvents · public/minn/src/Minn/Runtime/UserEvents.php · 102 lines

What the reference's REST users controller tells plugins, for the engine's own: with plugins loaded an account is written through the runtime's wp_insert_user, wp_update_user and wp_delete_user (wp_set_password, each profile meta, the role, clean_user_cache, user_register and the count, profile_update, delete_user and deleted_user), and the REST actions follow. Without a booted runtime each write is the engine's own, given as a closure.

Public

methodlive(): bool#

Whether plugins are loaded to be told anything.

methodcreate(array $userdata, string $role, Minn\Http\Request $request, Closure $quietly): int#

Creates an account the way the REST controller does: wp_insert_user with no role, rest_insert_user, then the role added, then rest_after_insert_user. Returns the new id.

$userdataarray<string, mixed>wp_insert_user's fields
$quietlyClosure(): intthe engine's own write
methodupdate(int $id, array $userdata, ?string $role, Minn\Http\Request $request, Closure $quietly): void#

Updates an account: wp_update_user with the changed fields, the role when one is given, then the two REST actions.

$userdataarray<string, mixed>the fields the request changes
$quietlyClosure(): voidthe engine's own write
methoddelete(int $id, ?int $reassign, array $data, Minn\Http\Request $request, Closure $quietly): void#

Deletes an account, its posts going to $reassign (or with it when none), then rest_delete_user with the account as it was.

$dataarray<string, mixed>the response
$quietlyClosure(): voidthe engine's own delete

Internals 1

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

privateprepared(array $userdata, WP_REST_Request $request): array#

rest_pre_insert_user over the prepared user (the request's fields), as the reference runs it before the save; what the filter changes is saved, an error refuses.

$userdataarray<string, mixed>
@return array<string, mixed>