WordPress.org

Ready to get started?Download WordPress

Forums

make password invalid once logged out of password protected page (3 posts)

  1. southcast
    Member
    Posted 9 months ago #

    In a wp-based site I have a custom form which I needed to hide from general public and give access to only a selected few who would then get a password from me, enter it and access the form and submit it. On form-submit I redirect them to another page. I have employed this bit of code below in my functions.php, which logs them out of the password-protected page, once redirected.

    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);
    }

    Now the twist, once any of these selected few are logged out of the password-protected page, I needed the password to become invalid. Not necessarily but sort of like a one-time password. Let me know if it is possible or either ways. A solution would be great if not please give me some pointers or alternatives. Thanks in advance.

  2. Timothy Jacobs
    Member
    Posted 9 months ago #

    Take a look at wp_update_post. Once you log them out, you can update the post_password with a randomly generated string.

  3. southcast
    Member
    Posted 8 months ago #

    @timothy that is a possibility yes, thanks for the suggestion.

Reply

You must log in to post.

About this Topic

Tags