Keeping user logged in whilst completing a form?

I have an assessment form that a user completes by rating lots of statements, with one per page. It takes about 45 minutes to complete before the user submits. The user must be logged in, in order to access the form. However, sometimes - because of the length of the form, the user can get logged out automatically while completing it. This results in the them being half way through the form and then being presented with a message telling them that they must log in to complete the form - is there a way to keep the user logged in whilst saving the form or for it to even be automatically saved as they complete it so they can return to it in the event of an error such as this?

Would be grateful for any suggestions!
thanks - Stephen

You can utilize the auth_cookie_expiration hook to extend how long user sessions are kept active for.

By default, it’s kept active for 14 days.

Here’s an example that would keep it active for 28 days:

<?php

add_filter( 'auth_cookie_expiration', function( $expiration_length, $user_id, $remember ) {
    return 28 * DAY_IN_SECONDS;
}, 10, 3 );
2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.