How is $current_user populated and how to force it to be populated

So I was looking how the $current_user global gets initialized with proper information and couldn’t find anything about it.

EntryPoint just creates a $current_user variable with a fresh empty User object, but it doesn’t try to even make it to have information about actual current user. Currently I am trying to get such info on somewhat external page in which I include some of the CRM files/logic. But $current_user stays unpopulated. I force it to be populated by doing $current_user->retrieve($_COOKIE['ck_login_id_20']). But this is not a perfect solution and I wonder how can I force CRM preferences/globals into a custom page.

The CRM process to populate the $current_user is first it presents you with the login form, which you can check at modules/Users/Login.php (and login.tpl)
When filled and submitted, it calls modules/Users/Authenticate.php ( check the line $authController->login($user_name, $password); )

The login function is defined in modules/Users/authentication/AuthenticationController.php

1 Like