Password protected page with a form submits for me fine but for others redirects them back to the password prompt

I have a custom coded page (using a page-xxx.php template). This page defined in the /Pages area of the WP admin has password protection.

The content in my custom template is a form and so that is naturally what you see once past the PW prompt I’ve setup. The issue is that for some users (not me, I’ve never been able to recreate the issue) is that when they have completed the form, upon submitting it, instead of reloading the same page with a success msg it reloads the same page but it doesn’t seem to remember that they have already got past the password prompt.

Can anyone assist troubleshooting this? I don’t know how a password protected WP page is functioning (via session vars/cookies?) but I had assumed that once past it, you could reload it/submit a form on it and you wouldn’t need to then get past the PW again.

Can anyone clarify this?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

When a user logs into a protected page, WordPress sets a cookie. We can check for the existence of that cookie with this conditional:

if ( isset( $_COOKIE['wp-postpass_' . COOKIEHASH] ) ) {
  // Do stuff. 
}

Also, you should be aware that only one password is stored in cookies at a time, to the last entry viewed.

By default, the cookie expires 10 days from creation

If you need to change

add_filter('post_password_expires', 'true_change_pass_exp', 10, 1);
function true_change_pass_exp( $exp ){
    return time() + 5 * DAY_IN_SECONDS; // 5 days
}


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x