API: New function to fetch current user id

This commit is contained in:
Michael 2021-05-03 05:25:54 +00:00
parent 4395f73d1e
commit 10a6f0a98f
2 changed files with 27 additions and 1 deletions

View file

@ -91,6 +91,22 @@ class BaseApi extends BaseModule
return (bool)self::$current_user_id;
}
/**
* Get current user id, returns 0 if not logged in
*
* @return int User ID
*/
protected static function getCurrentUserID()
{
if (is_null(self::$current_user_id)) {
api_login(DI::app(), false);
self::$current_user_id = api_user();
}
return (int)self::$current_user_id;
}
/**
* Get user info array.
*