WordPress Cookie Security – Persistent Cookie comment_author change to session cookie

Can someone explain to me how I would go about changing WordPress comment_author cookie expiery tag, I want to delete the 'Expires=' tag to change it to a session cookie.

Where would i do this in the php files?

Read More

Thanks

Related posts

Leave a Reply

1 comment

  1. If you just want to change expiration date, you can use comment_cookie_lifetime filter.

    E.g. to expire it after two years:

    add_filter('comment_cookie_lifetime', 2*YEAR_IN_SECONDS);
    

    To change it to session, you need to remove default wp_set_comment_cookies from set_comment_cookies hook and add your own one to set session cookie.

    Example:

    remove_action('set_comment_cookies', 'wp_set_comment_cookies', 10, 2);
    
    add_action('set_comment_cookies', function(WP_Comment $comment, WP_User $user)
    {
        // set session
    }, 10, 2);