The UsersService manages WordPress users. You can retrieve user details, update profiles, and manage authentication context.
Access via the facade:
$usersService = $wp->users();Retrieve the profile of the currently authenticated user.
$me = $wp->users()->me();
echo "Hello, " . $me->name;$users = $wp->users()->list(['roles' => 'editor']);
foreach ($users as $user) {
echo $user->name . "\n";
}$user = $wp->users()->get(1);$user = $wp->users()->create([
'username' => 'jdoe',
'email' => 'jdoe@example.com',
'password' => 'secret123',
'roles' => ['author']
]);$wp->users()->update(5, [
'first_name' => 'John',
'last_name' => 'Doe'
]);Requires reassigning posts to another user if not force deleting (though logic might vary based on WP configuration).
$wp->users()->delete(5, force: true, reassign: 1); // Logic depends on args allowed by WP APINote: The SDK
deletemethod signature strictly acceptsidandforce. Additional arguments likereassignmust be passed via theforcelogic or extended if supported. Currently, standarddeletesupportsforce.