Make WordPress Core


Ignore:
Timestamp:
05/28/2007 06:34:06 PM (17 years ago)
Author:
ryan
Message:

Better draft, private, and future post/page management from mdawaffe. fixes #3945

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/query.php

    r5530 r5575  
    996996
    997997        if ( $this->is_attachment ) {
    998             $where .= " AND (post_type = 'attachment')";
     998            $where .= " AND post_type = 'attachment'";
    999999        } elseif ($this->is_page) {
    1000             $where .= " AND (post_type = 'page')";
     1000            $where .= " AND post_type = 'page'";
    10011001        } elseif ($this->is_single) {
    1002             $where .= " AND (post_type = 'post')";
     1002            $where .= " AND post_type = 'post'";
    10031003        } else {
    1004             $where .= " AND (post_type = '$post_type' AND (post_status = 'publish'";
     1004            $where .= " AND post_type = '$post_type'";
     1005        }
     1006
     1007        if ( isset($q['post_status']) && '' != $q['post_status'] ) {
     1008            $q_status = explode(',', $q['post_status']);
     1009            $r_status = array();
     1010            if ( in_array( 'draft'  , $q_status ) )
     1011                $r_status[] = "post_status = 'draft'";
     1012            if ( in_array( 'future' , $q_status ) )
     1013                $r_status[] = "post_status = 'future'";
     1014            if ( in_array( 'inherit' , $q_status ) )
     1015                $r_status[] = "post_status = 'inherit'";
     1016            if ( in_array( 'private', $q_status ) )
     1017                $r_status[] = "post_status = 'private'";
     1018            if ( in_array( 'publish', $q_status ) )
     1019                $r_status[] = "post_status = 'publish'";
     1020            if ( !empty($r_status) )
     1021                $where .= " AND (" . join( ' OR ', $r_status ) . ")";
     1022        } elseif ( !$this->is_singular ) {
     1023            $where .= " AND (post_status = 'publish'";
    10051024
    10061025            if ( is_admin() )
    10071026                $where .= " OR post_status = 'future' OR post_status = 'draft'";
    10081027
    1009             if ( is_user_logged_in() ) {
    1010                 if ( 'post' == $post_type )
    1011                     $cap = 'read_private_posts';
    1012                 else
    1013                     $cap = 'read_private_pages';
    1014 
    1015                 if ( current_user_can($cap) )
    1016                     $where .= " OR post_status = 'private'";
    1017                 else
    1018                 $where .= " OR post_author = $user_ID AND post_status = 'private'";
    1019             }
    1020 
    1021             $where .= '))';
     1028            $where .= current_user_can( "read_private_{$post_type}s" ) ? " OR post_status = 'private'" : " OR post_author = $user_ID AND post_status = 'private'";
     1029
     1030            $where .= ')';
    10221031        }
    10231032
Note: See TracChangeset for help on using the changeset viewer.