How to use login forward correctly?


Here is what I'm trying to do:

elgg_register_plugin_hook_handler('login:forward', 'user', function (\Elgg\Hook $hook) {
  if($forward_url = $hook->getParam('forward')) {
    return $forward_url;
This does not work in all scenarios.
When entering the site, the user is redirected to the main page but not to the link specified in the "forward" parameter.
I was trying to modify core files, for example /action/login and _elgg_get_login_forward_url function, but that doesn't help.

I also didn't find any examples in existing plugins.

What am I doing wrong?
Thanks for any help.
  • See the function _elgg_get_login_forward_url() in vendor/elgg/elgg/engine/lib/sessions.php to understand what variables the hook is called with. The parameter array has no 'forward' attribute defined. Try

    if ($forward_url = $hook->getValue()) {
        return $forward_url;

    Or use the existing attributes of the params aray (request, user, source) if needed to achive what you have in mind.