Skip to content

Latest commit

 

History

History
65 lines (46 loc) · 1.31 KB

File metadata and controls

65 lines (46 loc) · 1.31 KB

Users Service

The UsersService manages WordPress users. You can retrieve user details, update profiles, and manage authentication context.

Usage

Access via the facade:

$usersService = $wp->users();

Get Current User (Me)

Retrieve the profile of the currently authenticated user.

$me = $wp->users()->me();
echo "Hello, " . $me->name;

List Users

$users = $wp->users()->list(['roles' => 'editor']);

foreach ($users as $user) {
    echo $user->name . "\n";
}

Get a User

$user = $wp->users()->get(1);

Create a User

$user = $wp->users()->create([
    'username' => 'jdoe',
    'email'    => 'jdoe@example.com',
    'password' => 'secret123',
    'roles'    => ['author']
]);

Update a User

$wp->users()->update(5, [
    'first_name' => 'John',
    'last_name'  => 'Doe'
]);

Delete a User

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 API

Note: The SDK delete method signature strictly accepts id and force. Additional arguments like reassign must be passed via the force logic or extended if supported. Currently, standard delete supports force.