• Resolved CobaltCat

    (@cobaltcat)


    Is there any way to set it up so that when someone is logged into a password protected page, they will automatically be logged out when they either leave the page or after a certain period of time? I’ve looked all over and can’t seem to find anything that will accomplish this.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator cubecolour

    (@numeeja)

    Make a new folder in your plugins directory called ‘post-password-expire-with-session’

    within this create a file called ‘post-password-expire-with-session.php’ and copy in the following code:

    <?php
    /*
    Plugin Name: Post Password Expire with session
    Description: Forces password protected posts to prompt for a password each time they are accessed
    Version: 1.0.0
    License: GPL2
    */
    
    function post_pw_expire_with_session() {
    	// Set a time of 0 in setcookie() to force the cookie to expire with the session
    	if ( isset( $_COOKIE['wp-postpass_' . COOKIEHASH] ) )
    	setcookie('wp-postpass_' . COOKIEHASH, '', 0, COOKIEPATH);
    }
    
    add_action( 'wp', 'post_pw_expire_with_session' );

    After activating this ‘Post Password Expire with session’ plugin visitors should need to enter the password every time they visit the page.

    Thread Starter CobaltCat

    (@cobaltcat)

    Thank you! That worked perfectly!

    That solution is too cool! Thanks, that was exactly what I was looking for as well.

    Hi;

    I have 5 costumers and i will make 5 different password protected pages for them. Sometimes i will send them passwords to see their pages. But when they are logged out, they can’t be logged in again.

    How can it be possible?

    Thanks in advance, my best regards;

    Ahmet

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Auto logout password protected pages and posts’ is closed to new replies.