Make WordPress Core


Ignore:
Timestamp:
02/29/2008 09:49:49 PM (19 years ago)
Author:
ryan
Message:

Add option to check caps when querying a particular post status. fixes #6052

File:
1 edited

Legend:

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

    r7070 r7109  
    12141214                        $q_status = explode(',', $q['post_status']);
    12151215                        $r_status = array();
     1216                        $p_status = array();
    12161217                        if ( in_array( 'draft'  , $q_status ) )
    12171218                                $r_status[] = "post_status = 'draft'";
     
    12231224                                $r_status[] = "post_status = 'inherit'";
    12241225                        if ( in_array( 'private', $q_status ) )
    1225                                 $r_status[] = "post_status = 'private'";
     1226                                $p_status[] = "post_status = 'private'";
    12261227                        if ( in_array( 'publish', $q_status ) )
    12271228                                $r_status[] = "post_status = 'publish'";
    1228                         if ( !empty($r_status) )
    1229                                 $where .= " AND (" . join( ' OR ', $r_status ) . ")";
     1229
     1230                        if ( empty($q['perm'] ) || 'readable' != $q['perm'] ) {
     1231                                $r_status = array_merge($r_status, $p_status);
     1232                                unset($p_status);
     1233                        }
     1234
     1235                        if ( !empty($r_status) ) {
     1236                                if ( !empty($q['perm'] ) && 'editable' == $q['perm'] && !current_user_can("edit_others_{$post_type}s") )
     1237                                        $where .= " AND (post_author = $user_ID " .  "AND (" . join( ' OR ', $r_status ) . "))";
     1238                                else
     1239                                        $where .= " AND (" . join( ' OR ', $r_status ) . ")";
     1240                        }
     1241                        if ( !empty($p_status) ) {
     1242                                if ( !empty($q['perm'] ) && 'readable' == $q['perm'] && !current_user_can("read_private_{$post_type}s") )
     1243                                        $where .= " AND (post_author = $user_ID " .  "AND (" . join( ' OR ', $p_status ) . "))";
     1244                                else
     1245                                        $where .= " AND (" . join( ' OR ', $p_status ) . ")";
     1246                        }
    12301247                } elseif ( !$this->is_singular ) {
    12311248                        $where .= " AND (post_status = 'publish'";
Note: See TracChangeset for help on using the changeset viewer.