diff --git src/wp-includes/query.php src/wp-includes/query.php
index 053f4e9..a8e6afe 100644
|
|
|
class WP_Query { |
| 3644 | 3644 | |
| 3645 | 3645 | // Check post status to determine if post should be displayed. |
| 3646 | 3646 | if ( !empty($this->posts) && ($this->is_single || $this->is_page) ) { |
| 3647 | | $status = get_post_status($this->posts[0]); |
| 3648 | | if ( 'attachment' === $this->posts[0]->post_type && 0 === (int) $this->posts[0]->post_parent ) { |
| 3649 | | $this->is_page = false; |
| 3650 | | $this->is_single = true; |
| 3651 | | $this->is_attachment = true; |
| 3652 | | } |
| 3653 | | $post_status_obj = get_post_status_object($status); |
| | 3647 | foreach ( $this->posts as $post_index => $_post ) { |
| | 3648 | $status = get_post_status( $_post ); |
| | 3649 | if ( 'attachment' === $_post->post_type && 0 === (int) $_post->post_parent ) { |
| | 3650 | $this->is_page = false; |
| | 3651 | $this->is_single = true; |
| | 3652 | $this->is_attachment = true; |
| | 3653 | } |
| | 3654 | $post_status_obj = get_post_status_object($status); |
| 3654 | 3655 | |
| 3655 | | // If the post_status was specifically requested, let it pass through. |
| 3656 | | if ( !$post_status_obj->public && ! in_array( $status, $q_status ) ) { |
| | 3656 | // If the post_status was specifically requested, let it pass through. |
| | 3657 | if ( !$post_status_obj->public && ! in_array( $status, $q_status ) ) { |
| 3657 | 3658 | |
| 3658 | | if ( ! is_user_logged_in() ) { |
| 3659 | | // User must be logged in to view unpublished posts. |
| 3660 | | $this->posts = array(); |
| 3661 | | } else { |
| 3662 | | if ( $post_status_obj->protected ) { |
| 3663 | | // User must have edit permissions on the draft to preview. |
| 3664 | | if ( ! current_user_can($edit_cap, $this->posts[0]->ID) ) { |
| 3665 | | $this->posts = array(); |
| | 3659 | if ( ! is_user_logged_in() ) { |
| | 3660 | // User must be logged in to view unpublished posts. |
| | 3661 | unset( $this->posts[ $post_index ] ); |
| | 3662 | } else { |
| | 3663 | if ( $post_status_obj->protected ) { |
| | 3664 | // User must have edit permissions on the draft to preview. |
| | 3665 | if ( ! current_user_can($edit_cap, $_post->ID) ) { |
| | 3666 | unset( $this->posts[ $post_index ] ); |
| | 3667 | } else { |
| | 3668 | $this->is_preview = true; |
| | 3669 | if ( 'future' != $status ) |
| | 3670 | $this->posts[ $post_index ]->post_date = current_time('mysql'); |
| | 3671 | } |
| | 3672 | } elseif ( $post_status_obj->private ) { |
| | 3673 | if ( ! current_user_can($read_cap, $this->posts[ $post_index ]->ID) ) |
| | 3674 | unset( $this->posts[ $post_index ] ); |
| 3666 | 3675 | } else { |
| 3667 | | $this->is_preview = true; |
| 3668 | | if ( 'future' != $status ) |
| 3669 | | $this->posts[0]->post_date = current_time('mysql'); |
| | 3676 | unset( $this->posts[ $post_index ] ); |
| 3670 | 3677 | } |
| 3671 | | } elseif ( $post_status_obj->private ) { |
| 3672 | | if ( ! current_user_can($read_cap, $this->posts[0]->ID) ) |
| 3673 | | $this->posts = array(); |
| 3674 | | } else { |
| 3675 | | $this->posts = array(); |
| 3676 | 3678 | } |
| 3677 | 3679 | } |
| 3678 | | } |
| 3679 | 3680 | |
| 3680 | | if ( $this->is_preview && $this->posts && current_user_can( $edit_cap, $this->posts[0]->ID ) ) { |
| 3681 | | /** |
| 3682 | | * Filter the single post for preview mode. |
| 3683 | | * |
| 3684 | | * @since 2.7.0 |
| 3685 | | * |
| 3686 | | * @param WP_Post $post_preview The Post object. |
| 3687 | | * @param WP_Query &$this The WP_Query instance (passed by reference). |
| 3688 | | */ |
| 3689 | | $this->posts[0] = get_post( apply_filters_ref_array( 'the_preview', array( $this->posts[0], &$this ) ) ); |
| | 3681 | if ( $this->is_preview && $this->posts && current_user_can( $edit_cap, $_post->ID ) ) { |
| | 3682 | /** |
| | 3683 | * Filter the single post for preview mode. |
| | 3684 | * |
| | 3685 | * @since 2.7.0 |
| | 3686 | * |
| | 3687 | * @param WP_Post $post_preview The Post object. |
| | 3688 | * @param WP_Query &$this The WP_Query instance (passed by reference). |
| | 3689 | */ |
| | 3690 | $this->posts[ $post_index ] = get_post( apply_filters_ref_array( 'the_preview', array( $this->posts[ $post_index ], &$this ) ) ); |
| | 3691 | } |
| 3690 | 3692 | } |
| | 3693 | |
| | 3694 | $this->posts = array_values( $this->posts ); |
| 3691 | 3695 | } |
| 3692 | 3696 | |
| 3693 | 3697 | // Put sticky posts at the top of the posts array |