Skip to main content

Save custom field via plugin

How do you save a user custom field in PHP ? Easy as that!
$user = Craft::$app->getUser()->getIdentity();

$user->setFieldValues([
    'customField' => 1,
]);

Craft::$app->getElements()->saveElement($user);