• Resolved alexbosch

    (@alexbosch)


    Hi;

    I was searching a way to solve the incompatibility of cache time of your token and my cache plugin and I found this article on your website:

    https://wpforms.com/developers/how-to-change-the-cache-time-on-your-form-token/

    I want to apply that, but I don’t understand exactly what I have to write on the php inserter. If I want to allow a token cache for one week, should I use the next code?

    add_filter( 'wpforms_form_token_check_before_today', 'example_add_longer_token_time_before' );
     
        /**
         * Extend the expiration time. 
         */
        function example_add_longer_token_time_before( $times ) {
            // Allow the token to persist for 5 days
            $times[] = 7 * DAY_IN_SECONDS;
        }

    If not, could you please help me to solve that.

    Thank you in advance.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hey @alexbosch,

    Thanks for contacting us!

    You can use following code to extend the expiration time:

    add_filter( 'wpforms_form_token_check_before_today', function ( $times ) {  
    
       $times[] = 3 * DAY_IN_SECONDS;  
       $times[] = 4 * DAY_IN_SECONDS;  
       $times[] = 5 * DAY_IN_SECONDS;  
       $times[] = 6 * DAY_IN_SECONDS;  
       $times[] = 7 * DAY_IN_SECONDS;  
       $times[] = 8 * DAY_IN_SECONDS;  
    
    return $times; } );
    

    The above code would increase the token lifetime to 8 days and that should also fix the issue for you.

    Kindly,

    Thread Starter alexbosch

    (@alexbosch)

    Hi @prashantrai

    OK. I’ll try that.

    Thank you so much!

    You’re most welcome @alexbosch ??

    Hey @alexbosch – We haven’t heard back from you in about a week, so I’m going to go ahead and close this thread for now. But if you’d like us to assist further, please feel welcome to continue the conversation.

    Thanks!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Changing form token cache time’ is closed to new replies.