Ticket #2613: private_query.diff

File private_query.diff, 1.2 KB (added by ryan, 6 years ago)
  • wp-includes/query.php

     
    840840                } else { 
    841841                        $where .= " AND (post_type = '$post_type' AND (post_status = 'publish'"; 
    842842 
    843                         if ( is_admin() ) 
     843                        if ( is_admin() ) { 
    844844                                $where .= " OR post_status = 'future' OR post_status = 'draft'"; 
    845                         else 
    846                                 $distinct = 'DISTINCT'; 
    847          
    848                         if ( is_user_logged_in() ) 
    849                                 $where .= " OR post_author = $user_ID AND post_status = 'private'))"; 
    850                         else 
    851                                 $where .= '))'; 
     845 
     846                                // Users who can edit other's posts and pages can see all private posts. 
     847                                // Users who can edit only their own posts can see only their own private posts. 
     848                                if ( is_user_logged_in() ) { 
     849                                        if ( 'post' == $post_type ) 
     850                                                $cap = 'edit_others_posts'; 
     851                                        else 
     852                                                $cap = 'edit_others_pages'; 
     853                                        if ( current_user_can($cap) ) 
     854                                                $where .= "OR post_status = 'private'"; 
     855                                        else 
     856                                                $where .= " OR post_author = $user_ID AND post_status = 'private'"; 
     857                                } 
     858                        } 
     859                         
     860                        $where .= '))'; 
    852861                } 
    853862 
    854863                // Apply filters on where and join prior to paging so that any