Password protected post or page – error message by wrong password?

Ok guys, I’m building a page, where a certain sub-page is password protected. Easy in wordpress. But there is a UX problem: when a user enters a wrong password, theres no error message or something to indicate, that the password is not correct.

Is it posible to manually code it somehow to the template file?

Related posts

Leave a Reply

1 comment

  1. not really, but can try something like:

    add_action('wp', 'check_post_pass');
    
    function check_post_pass(){
    
      if(!is_single() || !post_password_required()) return;
    
      global $post;
      if(isset($_COOKIE['wp-postpass_'.COOKIEHASH])
          && $_COOKIE['wp-postpass_'.COOKIEHASH] !== $post->post_password){
    
        define('INVALID_POST_PASS', true);
    
        // tell the browser to remove the cookie so the message doesn't show up every time
        setcookie('wp-postpass_'.COOKIEHASH, NULL, -1, COOKIEPATH);
      }
    
    }   
    

    in your template:

    if(defined('INVALID_POST_PASS')) _e('The password you entered is funky');
    

    But a much better idea would be to create your own the_content()-like function and password form + check function, without cookies…