post_password_required(). fixes #7679
git-svn-id: https://develop.svn.wordpress.org/trunk@8800 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
341cede30b
commit
a487b60f71
@ -33,7 +33,7 @@ $commenter = wp_get_current_commenter();
|
||||
extract($commenter);
|
||||
$comments = get_approved_comments($id);
|
||||
$commentstatus = get_post($id);
|
||||
if (!empty($commentstatus->post_password) && $_COOKIE['wp-postpass_'. COOKIEHASH] != $commentstatus->post_password) { // and it doesn't match the cookie
|
||||
if ( post_password_required($commentstatus) ) { // and it doesn't match the cookie
|
||||
echo(get_the_password_form());
|
||||
} else { ?>
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
<?php if ( !empty($post->post_password) && $_COOKIE['wp-postpass_' . COOKIEHASH] != $post->post_password) : ?>
|
||||
<?php if ( post_password_required() ) : ?>
|
||||
<p><?php _e('Enter your password to view comments.'); ?></p>
|
||||
<?php return; endif; ?>
|
||||
|
||||
|
@ -33,7 +33,7 @@ $commenter = wp_get_current_commenter();
|
||||
extract($commenter);
|
||||
$comments = get_approved_comments($id);
|
||||
$post = get_post($id);
|
||||
if (!empty($post->post_password) && $_COOKIE['wp-postpass_'. COOKIEHASH] != $post->post_password) { // and it doesn't match the cookie
|
||||
if ( post_password_required($post) ) { // and it doesn't match the cookie
|
||||
echo(get_the_password_form());
|
||||
} else { ?>
|
||||
|
||||
|
@ -2,16 +2,11 @@
|
||||
if (!empty($_SERVER['SCRIPT_FILENAME']) && 'comments.php' == basename($_SERVER['SCRIPT_FILENAME']))
|
||||
die ('Please do not load this page directly. Thanks!');
|
||||
|
||||
if (!empty($post->post_password)) { // if there's a password
|
||||
if ($_COOKIE['wp-postpass_' . COOKIEHASH] != $post->post_password) { // and it doesn't match the cookie
|
||||
?>
|
||||
|
||||
if ( post_password_required() ) { ?>
|
||||
<p class="nocomments">This post is password protected. Enter the password to view comments.</p>
|
||||
|
||||
<?php
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* This variable is for alternating comment background */
|
||||
$oddcomment = 'alt';
|
||||
|
@ -802,12 +802,10 @@ function comments_popup_link( $zero = 'No Comments', $one = '1 Comment', $more =
|
||||
return;
|
||||
}
|
||||
|
||||
if ( !empty($post->post_password) ) { // if there's a password
|
||||
if ( !isset($_COOKIE['wp-postpass_' . COOKIEHASH]) || $_COOKIE['wp-postpass_' . COOKIEHASH] != $post->post_password ) { // and it doesn't match the cookie
|
||||
if ( post_password_required() ) {
|
||||
echo __('Enter your password to view comments');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
echo '<a href="';
|
||||
if ( $wpcommentsjavascript ) {
|
||||
|
@ -394,8 +394,7 @@ function html_type_rss() {
|
||||
* @uses get_post_custom() To get the current post enclosure metadata.
|
||||
*/
|
||||
function rss_enclosure() {
|
||||
global $post;
|
||||
if ( !empty($post->post_password) && (!isset($_COOKIE['wp-postpass_'.COOKIEHASH]) || $_COOKIE['wp-postpass_'.COOKIEHASH] != $post->post_password) )
|
||||
if ( post_password_required() )
|
||||
return;
|
||||
|
||||
foreach ( (array) get_post_custom() as $key => $val) {
|
||||
@ -426,8 +425,7 @@ function rss_enclosure() {
|
||||
* @uses get_post_custom() To get the current post enclosure metadata.
|
||||
*/
|
||||
function atom_enclosure() {
|
||||
global $post;
|
||||
if ( !empty($post->post_password) && ($_COOKIE['wp-postpass_'.COOKIEHASH] != $post->post_password) )
|
||||
if ( post_password_required() )
|
||||
return;
|
||||
|
||||
foreach ( (array) get_post_custom() as $key => $val ) {
|
||||
|
@ -90,12 +90,10 @@ function get_the_content($more_link_text = NULL, $stripteaser = 0, $more_file =
|
||||
|
||||
$output = '';
|
||||
|
||||
if ( !empty($post->post_password) ) { // if there's a password
|
||||
if ( !isset($_COOKIE['wp-postpass_'.COOKIEHASH]) || stripslashes($_COOKIE['wp-postpass_'.COOKIEHASH]) != $post->post_password ) { // and it doesn't match the cookie
|
||||
if ( post_password_required($post) ) { // If post password required and it doesn't match the cookie
|
||||
$output = get_the_password_form();
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
|
||||
if ( $more_file != '' )
|
||||
$file = $more_file;
|
||||
@ -145,12 +143,10 @@ function get_the_excerpt($deprecated = '') {
|
||||
global $post;
|
||||
$output = '';
|
||||
$output = $post->post_excerpt;
|
||||
if ( !empty($post->post_password) ) { // if there's a password
|
||||
if ( !isset($_COOKIE['wp-postpass_'.COOKIEHASH]) || $_COOKIE['wp-postpass_'.COOKIEHASH] != $post->post_password ) { // and it doesn't match the cookie
|
||||
if ( post_password_required($post) ) {
|
||||
$output = __('There is no excerpt because this is a protected post.');
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
|
||||
return apply_filters('get_the_excerpt', $output);
|
||||
}
|
||||
@ -227,6 +223,33 @@ function get_post_class( $class = '', $post_id = null ) {
|
||||
return apply_filters('post_class', $classes, $class, $post_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if post requires a password and if the correct password has been provided
|
||||
*
|
||||
* {@internal Missing Long Description}}
|
||||
*
|
||||
* @package WordPress
|
||||
* @subpackage Post
|
||||
* @since 2.7
|
||||
*
|
||||
* @param int|object $post An optional post. Global $post used if not provided.
|
||||
* @return bool false if a password is not required or the correct password cookie is present, true otherwise
|
||||
*/
|
||||
function post_password_required( $post = null ) {
|
||||
$post = get_post($post);
|
||||
|
||||
if ( empty($post->post_password) )
|
||||
return false;
|
||||
|
||||
if ( !isset($_COOKIE['wp-postpass_' . COOKIEHASH]) )
|
||||
return true;
|
||||
|
||||
if ( $_COOKIE['wp-postpass_' . COOKIEHASH] != $post->post_password )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Echo "sticky" CSS class if a post is sticky
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user