I have a page that I want to password protect, but it is based on a page template that pulls in all the data to be displayed outside of WordPress, not from the post content. When I password protect the post, it does nothing to protect the content. How can I tie into the WordPress system to protect that content?
gregorylepacha
Member
Posted 3 years ago #
ericbarbosajr
Member
Posted 3 years ago #
BUMP!
i was hoping that get_the_content() would return false if the page is password protected. This way we can determine when to show a password prompt.
I'd really like to be able to tie into the password system.
darknailblue
Member
Posted 2 years ago #
i hear ya... I'm having the same problem... I started working on a plugin that will enable a conditional tag so that this is possible
I know that it is possible but haven't been getting anywhere with it...
darknailblue
Member
Posted 2 years ago #
Turns out I don't need to write a plugin that does this... The conditional function that you want to use is...
post_password_required()
Basically, this returns a true value if you are entered the password on the page or if the cookie is set.
It took some digging but, this helped me out a great deal...
cebradesign
Member
Posted 2 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...
}
(taken from wp support forum)
Hope it's clear or helpful...
In case you are looking to modify the generic "This post is password protected. To view.." form, you can add a filter into the functions.php file, like so:
<?php
add_filter('the_password_form', 'custom_the_password_form');
function custom_the_password_form() {
$output = 'YOUR CUSTOM FORM AND TEXT HERE';
return $output;
}
?>
You can view the original code in post-template.php on lines 1132 - 1141.