siga
9/26/2015 - 9:26 AM

Password-protected pages and posts

Password-protected pages and posts: By default WP sets a cookie that lasts 10 days. This means you don't need to re-enter the password for 10 days. This code overrides this and requires a password each time the page/post is visited. (FB, Wordpress Advanced group)

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, '', 0, COOKIEPATH);
}