I have been trying to get the current authenticated user ID in Hook_cron() function.
But Its showing only the anonymous user, though the current user is an authenticated user.
How Could I get the current authenticated user in hook_cron()
Drupal Answers is a question and answer site for Drupal developers and administrators. It only takes a minute to sign up.Sign up to join this community
There's no such thing - cron always runs as the anonymous user.
This is forced by the
drupal_cron_run() function in Drupal 7:
// Force the current user to anonymous to ensure consistent permissions on // cron runs. $original_user = $GLOBALS['user']; $GLOBALS['user'] = drupal_anonymous_user();
Cron::run in Drupal 8:
// Force the current user to anonymous to ensure consistent permissions on // cron runs. $this->accountSwitcher ->switchTo(new AnonymousUserSession());