Changeset 8800

Show
Ignore:
Timestamp:
09/03/08 19:54:14 (3 months ago)
Author:
ryan
Message:

post_password_required(). fixes #7679

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/wp-content/themes/classic/comments-popup.php

    r7450 r8800  
    3434$comments = get_approved_comments($id); 
    3535$commentstatus = get_post($id); 
    36 if (!empty($commentstatus->post_password) && $_COOKIE['wp-postpass_'. COOKIEHASH] != $commentstatus->post_password) {  // and it doesn't match the cookie 
     36if ( post_password_required($commentstatus) ) {  // and it doesn't match the cookie 
    3737    echo(get_the_password_form()); 
    3838} else { ?> 
  • trunk/wp-content/themes/classic/comments.php

    r8695 r8800  
    1 <?php if ( !empty($post->post_password) && $_COOKIE['wp-postpass_' . COOKIEHASH] != $post->post_password) : ?> 
     1<?php if ( post_password_required() ) : ?> 
    22<p><?php _e('Enter your password to view comments.'); ?></p> 
    33<?php return; endif; ?> 
  • trunk/wp-content/themes/default/comments-popup.php

    r7450 r8800  
    3434$comments = get_approved_comments($id); 
    3535$post = get_post($id); 
    36 if (!empty($post->post_password) && $_COOKIE['wp-postpass_'. COOKIEHASH] != $post->post_password) {  // and it doesn't match the cookie 
     36if ( post_password_required($post) ) {  // and it doesn't match the cookie 
    3737    echo(get_the_password_form()); 
    3838} else { ?> 
  • trunk/wp-content/themes/default/comments.php

    r8703 r8800  
    33        die ('Please do not load this page directly. Thanks!'); 
    44 
    5     if (!empty($post->post_password)) { // if there's a password 
    6         if ($_COOKIE['wp-postpass_' . COOKIEHASH] != $post->post_password) {  // and it doesn't match the cookie 
    7             ?> 
    8  
    9             <p class="nocomments">This post is password protected. Enter the password to view comments.</p> 
    10  
    11             <?php 
    12             return; 
    13         } 
     5    if ( post_password_required() ) { ?> 
     6        <p class="nocomments">This post is password protected. Enter the password to view comments.</p> 
     7    <?php 
     8        return; 
    149    } 
    1510 
  • trunk/wp-includes/comment-template.php

    r8695 r8800  
    803803    } 
    804804 
    805     if ( !empty($post->post_password) ) { // if there's a password 
    806         if ( !isset($_COOKIE['wp-postpass_' . COOKIEHASH]) || $_COOKIE['wp-postpass_' . COOKIEHASH] != $post->post_password ) {  // and it doesn't match the cookie 
    807             echo __('Enter your password to view comments'); 
    808             return; 
    809         } 
     805    if ( post_password_required() ) { 
     806        echo __('Enter your password to view comments'); 
     807        return; 
    810808    } 
    811809 
  • trunk/wp-includes/feed.php

    r8600 r8800  
    395395 */ 
    396396function rss_enclosure() { 
    397     global $post; 
    398     if ( !empty($post->post_password) && (!isset($_COOKIE['wp-postpass_'.COOKIEHASH]) || $_COOKIE['wp-postpass_'.COOKIEHASH] != $post->post_password) ) 
     397    if ( post_password_required() ) 
    399398        return; 
    400399 
     
    427426 */ 
    428427function atom_enclosure() { 
    429     global $post; 
    430     if ( !empty($post->post_password) && ($_COOKIE['wp-postpass_'.COOKIEHASH] != $post->post_password) ) 
     428    if ( post_password_required() ) 
    431429        return; 
    432430 
  • trunk/wp-includes/post-template.php

    r8643 r8800  
    9191    $output = ''; 
    9292 
    93     if ( !empty($post->post_password) ) { // if there's a password 
    94         if ( !isset($_COOKIE['wp-postpass_'.COOKIEHASH]) || stripslashes($_COOKIE['wp-postpass_'.COOKIEHASH]) != $post->post_password ) {   // and it doesn't match the cookie 
    95             $output = get_the_password_form(); 
    96             return $output; 
    97         } 
     93    if ( post_password_required($post) ) {  // If post password required and it doesn't match the cookie 
     94        $output = get_the_password_form(); 
     95        return $output; 
    9896    } 
    9997 
     
    146144    $output = ''; 
    147145    $output = $post->post_excerpt; 
    148     if ( !empty($post->post_password) ) { // if there's a password 
    149         if ( !isset($_COOKIE['wp-postpass_'.COOKIEHASH]) || $_COOKIE['wp-postpass_'.COOKIEHASH] != $post->post_password ) {  // and it doesn't match the cookie 
    150             $output = __('There is no excerpt because this is a protected post.'); 
    151             return $output; 
    152         } 
     146    if ( post_password_required($post) ) { 
     147        $output = __('There is no excerpt because this is a protected post.'); 
     148        return $output; 
    153149    } 
    154150 
     
    226222 
    227223    return apply_filters('post_class', $classes, $class, $post_id); 
     224} 
     225 
     226/** 
     227 * Determines if post requires a password and if the correct password has been provided 
     228 * 
     229 * {@internal Missing Long Description}} 
     230 * 
     231 * @package WordPress 
     232 * @subpackage Post 
     233 * @since 2.7 
     234 * 
     235 * @param int|object $post An optional post.  Global $post used if not provided. 
     236 * @return bool false if a password is not required or the correct password cookie is present, true otherwise 
     237 */ 
     238function post_password_required( $post = null ) { 
     239    $post = get_post($post); 
     240 
     241    if ( empty($post->post_password) ) 
     242        return false; 
     243 
     244    if ( !isset($_COOKIE['wp-postpass_' . COOKIEHASH]) ) 
     245        return true; 
     246 
     247    if ( $_COOKIE['wp-postpass_' . COOKIEHASH] != $post->post_password ) 
     248        return true; 
     249 
     250    return false; 
    228251} 
    229252