0

I added the following to the child-theme functions.php ///time out login so you must reenter it every time// add_action( 'wp', 'post_pw_sess_expire' ); function post_pw_sess_expire() { if ( isset( $_COOKIE['wp-postpass_' . COOKIEHASH] ) ) // Setting a time of 0 in setcookie() forces the cookie to expire with the session setcookie('wp-postpass_' . COOKIEHASH, $_COOKIE['wp-postpass_' . COOKIEHASH], time() + 1 * 5, COOKIEPATH); }

I replaced setcookie('wp-postpass_' . COOKIEHASH, '', 0, COOKIEPATH); with setcookie('wp-postpass_' . COOKIEHASH, $_COOKIE['wp-postpass_' . COOKIEHASH], time() + 1 * 5, COOKIEPATH); so that you must reenter the password after one minute on the page/per session.

If I open Chrome, go to the page, I go to http://happynick.com/marketing/extra/private/ and type "private" to enter page.

When I "Clear Browsing Data" and go back to http://happynick.com/marketing/extra/private/, I am asked to enter "private" each time. Great. But if I go back to the page without closing Chrome, I can still access the page WITHOUT being asked to enter the password.

In Firefox, I can access it without entering the password again, even after closing Firefox and clearing going to Preferences > Advanced > Cached Web Content > Clear now.

1 Answer 1

7

Stop what you're doing - it's so much simpler!

function wpse_191369_post_password_expires() {
    return time() + 10; // Expire in 10 seconds
}

add_filter( 'post_password_expires', 'wpse_191369_post_password_expires' );

That's all you need.

4
  • Thanks, but will this work with other pages? wpse_191369 looks it might only work on this page. How did you discover this number? Is this correct ///time out login so you must reenter it every time// add_action( 'wp', 'post_pw_sess_expire' ); function wpse_191369_post_password_expires() { return time() + 10; // Expire in 10 seconds } add_filter( 'post_password_expires', 'wpse_191369_post_password_expires' ); }
    – Nick
    Commented Jun 13, 2015 at 11:01
  • 2
    wpse_191369 is a prefix I use when naming functions in answers - WPSE = WordPress Stack Exchange, 191369 = the ID of this question. My answer is all the code you need. It overrides the default cookie timeout for all post passwords. You don't need to handle the cookie/password yourself i.e. You don't need post_pw_sess_expire or any of the code you've tried so far. Commented Jun 13, 2015 at 11:41
  • Which Is this correct? ///time out login so you must reenter it every time// add_action( 'wp', 'post_pw_sess_expire' ); function post_password_expires() { return time() + 10; // Expire in 10 seconds } add_filter( 'post_password_expires', 'post_password_expires' ); }
    – Nick
    Commented Jul 2, 2015 at 8:29
  • The following did not work. Help.
    – Nick
    Commented Jul 2, 2015 at 8:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.