WordPress.org

Ready to get started?Download WordPress

Forums

Custom Template to be protection aware. (3 posts)

  1. ericbarbosajr
    Member
    Posted 5 years ago #

    Can somebody give me some reference on:

    How to check if the post/page is password protected and whether the viewer has access (entered correct password).

    Ive been googling for hours now. :( . I was hoping theres some functions like.

    is_password_protected();
    and
    is_password_ok()
    anythin like that. :)

    Thanks.

  2. chaoskaizer
    Member
    Posted 5 years ago #

    How to check if the post/page is password protected

    2.5.1 doesnt have post_password_required() function so I think you can use ↓ (inside WP posts loop)

    if(!empty($post->post_password) and $_COOKIE['wp-postpass_' . COOKIEHASH] != $post->post_password)){
     // this post is password protected
    }

    ... whether the viewer has access (entered correct password).

    if (isset($_COOKIE['wp-postpass_' . COOKIEHASH])
     and $_COOKIE['wp-postpass_' . COOKIEHASH] == $post->post_password){
      // correct pass
    }
  3. cebradesign
    Member
    Posted 4 years ago #

    Could it be something like...

    if(!empty($post->post_password) and $_COOKIE['wp-postpass_' . COOKIEHASH] != $post->post_password)){
     // here what to tell the visitor: it's a protected page blah
    }
    the_content(); // here we ask WP to ask for a password, content should be blank
    
    if (isset($_COOKIE['wp-postpass_' . COOKIEHASH])
     and $_COOKIE['wp-postpass_' . COOKIEHASH] == $post->post_password){
      // here it's the protected stuff...
    }

Topic Closed

This topic has been closed to new replies.

About this Topic