| 1 | <?php |
|---|
| 2 | /** |
|---|
| 3 | * Filter `the_posts` to allow viewing of scheduled posts |
|---|
| 4 | * |
|---|
| 5 | * It can't be done via a capability check because core requires |
|---|
| 6 | * user to be logged in for non-public statuses |
|---|
| 7 | * |
|---|
| 8 | * @see https://core.trac.wordpress.org/browser/tags/3.8.1/src/wp-includes/query.php#L2972 |
|---|
| 9 | */ |
|---|
| 10 | function dbx_filter_the_posts_show_future( $posts, &$q ) { |
|---|
| 11 | global $wpdb; |
|---|
| 12 | |
|---|
| 13 | if ( ! $q->is_main_query() || ! $q->is_single || empty( $q->request ) || ! empty( $posts ) ) { |
|---|
| 14 | return $posts; |
|---|
| 15 | } |
|---|
| 16 | |
|---|
| 17 | $post = $wpdb->get_row( $q->request ); |
|---|
| 18 | if ( empty( $post ) ) { |
|---|
| 19 | return $posts; |
|---|
| 20 | } |
|---|
| 21 | |
|---|
| 22 | $post = get_post( $post->ID ); |
|---|
| 23 | if ( 'future' === $post->post_status ) { |
|---|
| 24 | return array( $post ); |
|---|
| 25 | } else { |
|---|
| 26 | return $posts; |
|---|
| 27 | } |
|---|
| 28 | |
|---|
| 29 | } |
|---|
| 30 | add_filter( 'the_posts', 'dbx_filter_the_posts_show_future', 10, 2 ); |
|---|