Site logo

Archived topic

Page caching and prefilling the comments form

3 replies · Started by genstone88 on April 21, 2022

Viewing posts 1–4 of 4

I'm working on customizing the Wordpress comments form in my GeneratePress child theme and have been using some tips from the forum such as the one suggested here:
https://generatepress.com/forums/topic/comment-cookies-consent-label/

Now I realize though that functions like wp_get_current_commenter(); are doing stuff based on the “comment_author_email_{HASH}” cookie and “comment_author_{HASH}” cookie.
That's very nice of course but on the other hand I was also planning on using a page cache solution, including also for the single post pages.
Wouldn't this result in caching issues in the sense that if a user, who has the comments cookies already set, opens such a page, then the page gets cached including any content that is customized based on the value of such cookies. In this example it could be HTML output which determines whether a checkbox in the form is already checked upon opening the page or not. Then if another user opens the page, that user would get the cached version regardless on his/her own cookie values.

Or, worse yet, Wordpress also allows for prefilling Name and Email in the comments form based on the comments cookies. I believe this is being done server side using PHP logic or is that not the case? If so, then such prefilled personal data would be cached if the posts page (with a comment form) is cached by the page cache? And the following user would hit such cache and see the personal details of the first user in the comments form?
Is GeneratePress doing anything specific in relation to prefilling the comments form or is that all default Wordpress functionality/behavior? And would I indeed have a serious caching issue when including a posts page that has a comments form in the page cache? Or am I missing something?

Hi there,

GeneratePress simply calls the WordPress core comment_form() function, we don't interfere its behaviour in any way.

When it comes to caching you would need to check the options of the cache you're using. Some may have dedicated Comment Form caching options.

Thanks for the answer David!
It steered me in the right direction.
I had a look at the function you mentioned https://developer.wordpress.org/reference/functions/comment_form/ and indeed it has PHP logic based on the user's cookies. So a full page cache which would ignore the fact that a user already has comments cookies set, would indeed result in issues as the page cache would end up caching the user's details in the form, for others to see.
I did some testing but realized the page cache solution of my hosting provider already excludes such scenario from the page cache, and thus bypasses the page cache in case the comments cookies are set. So any user with comments cookies (and thus a prefilled comments form) won't trigger the page cache, and the page cache system should therefore never create a cached version of the page they get served.
And that means that also any comments that are still in moderation won't be cached in the page cache etc.

So I guess I can happily work wp_get_current_commenter(); into my PHP logic, knowing that it shouldn't result in issues with page cache. Depending on the page cache system used it definitely COULD result in issues but fortunately enough not with the system that I'm using.

Awesome - sounds like you got what you need ! Glad to be a tiny bit of help!

This archived topic is closed to new replies.