3076 | | if ( $post_status_obj && ! $post_status_obj->public ) { |
3077 | | if ( ! is_user_logged_in() ) { |
3078 | | // User must be logged in to view unpublished posts. |
3079 | | $this->posts = array(); |
3080 | | } else { |
3081 | | if ( $post_status_obj->protected ) { |
3082 | | // User must have edit permissions on the draft to preview. |
3083 | | if ( ! current_user_can( $edit_cap, $this->posts[0]->ID ) ) { |
3084 | | $this->posts = array(); |
| 3082 | if ( $post_status_obj && ! $post_status_obj->public ) { |
| 3083 | if ( ! is_user_logged_in() ) { |
| 3084 | // User must be logged in to view unpublished posts. |
| 3085 | unset( $this->posts[$i] ); |
| 3086 | } else { |
| 3087 | if ( $post_status_obj->protected ) { |
| 3088 | // User must have edit permissions on the draft to preview. |
| 3089 | if ( ! current_user_can( $edit_cap, $this->posts[$i]->ID ) ) { |
| 3090 | unset( $this->posts[$i] ); |
| 3091 | } else { |
| 3092 | $this->is_preview = true; |
| 3093 | if ( 'future' != $status ) { |
| 3094 | $this->posts[$i]->post_date = current_time( 'mysql' ); |
| 3095 | } |
| 3096 | } |
| 3097 | } elseif ( $post_status_obj->private ) { |
| 3098 | if ( ! current_user_can( $read_cap, $this->posts[$i]->ID ) ) { |
| 3099 | unset( $this->posts[$i] ); |
| 3100 | } |
3107 | | if ( $this->is_preview && $this->posts && current_user_can( $edit_cap, $this->posts[0]->ID ) ) { |
3108 | | /** |
3109 | | * Filters the single post for preview mode. |
3110 | | * |
3111 | | * @since 2.7.0 |
3112 | | * |
3113 | | * @param WP_Post $post_preview The Post object. |
3114 | | * @param WP_Query $this The WP_Query instance (passed by reference). |
3115 | | */ |
3116 | | $this->posts[0] = get_post( apply_filters_ref_array( 'the_preview', array( $this->posts[0], &$this ) ) ); |
3117 | | } |
3118 | | } |
3119 | | |
3120 | | // Put sticky posts at the top of the posts array. |
3121 | | $sticky_posts = get_option( 'sticky_posts' ); |
3122 | | if ( $this->is_home && $page <= 1 && is_array( $sticky_posts ) && ! empty( $sticky_posts ) && ! $q['ignore_sticky_posts'] ) { |
3123 | | $num_posts = count( $this->posts ); |
3124 | | $sticky_offset = 0; |
3125 | | // Loop over posts and relocate stickies to the front. |
3126 | | for ( $i = 0; $i < $num_posts; $i++ ) { |
3127 | | if ( in_array( $this->posts[ $i ]->ID, $sticky_posts ) ) { |
3128 | | $sticky_post = $this->posts[ $i ]; |
3129 | | // Remove sticky from current position. |
3130 | | array_splice( $this->posts, $i, 1 ); |
3131 | | // Move to front, after other stickies. |
3132 | | array_splice( $this->posts, $sticky_offset, 0, array( $sticky_post ) ); |
3133 | | // Increment the sticky offset. The next sticky will be placed at this offset. |
3134 | | $sticky_offset++; |
3135 | | // Remove post from sticky posts array. |
3136 | | $offset = array_search( $sticky_post->ID, $sticky_posts ); |
3137 | | unset( $sticky_posts[ $offset ] ); |
| 3113 | if ( $this->is_preview && $this->posts && current_user_can( $edit_cap, $this->posts[$i]->ID ) ) { |
| 3114 | /** |
| 3115 | * Filters the single post for preview mode. |
| 3116 | * |
| 3117 | * @since 2.7.0 |
| 3118 | * |
| 3119 | * @param WP_Post $post_preview The Post object. |
| 3120 | * @param WP_Query $this The WP_Query instance (passed by reference). |
| 3121 | */ |
| 3122 | $this->posts[$i] = get_post( apply_filters_ref_array( 'the_preview', array( $this->posts[$i], &$this ) ) ); |
3140 | | |
3141 | | // If any posts have been excluded specifically, Ignore those that are sticky. |
3142 | | if ( ! empty( $sticky_posts ) && ! empty( $q['post__not_in'] ) ) { |
3143 | | $sticky_posts = array_diff( $sticky_posts, $q['post__not_in'] ); |
3144 | | } |
3145 | | |
3146 | | // Fetch sticky posts that weren't in the query results. |
3147 | | if ( ! empty( $sticky_posts ) ) { |
3148 | | $stickies = get_posts( |
3149 | | array( |
3150 | | 'post__in' => $sticky_posts, |
3151 | | 'post_type' => $post_type, |
3152 | | 'post_status' => 'publish', |
3153 | | 'nopaging' => true, |
3154 | | ) |
3155 | | ); |
3156 | | |
3157 | | foreach ( $stickies as $sticky_post ) { |
3158 | | array_splice( $this->posts, $sticky_offset, 0, array( $sticky_post ) ); |
3159 | | $sticky_offset++; |
3160 | | } |
3161 | | } |
| 3125 | $this->posts = array_merge( $this->posts ); |