Function: set_current_user

set_current_user( integer | null $id, string $name )

Changes the current user by ID or name.

Set $id to null and specify a name if you do not know a user's ID.


Name Type(s) Default Value Description
$id integer | null

User ID.

$name string ''

Optional. The user's username



returns wp_set_current_user()

WordPress Developer Newsletter

Stay on top of the latest WordPress API changes, developer tool updates, security alerts and more.