From e19c9ab70c063c686bf07336f4b7ae2a9074173e Mon Sep 17 00:00:00 2001 From: ryan Date: Sun, 6 Nov 2005 07:04:46 +0000 Subject: [PATCH] Preview future dated posts. Props davidhouse. fixes #1795 git-svn-id: http://svn.automattic.com/wordpress/trunk@3001 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/classes.php | 19 ++++++++++++++++--- wp-includes/functions.php | 6 ++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/wp-includes/classes.php b/wp-includes/classes.php index deab5fff75..e19734cb9f 100644 --- a/wp-includes/classes.php +++ b/wp-includes/classes.php @@ -13,6 +13,7 @@ class WP_Query { var $post; var $is_single = false; + var $is_preview = false; var $is_page = false; var $is_archive = false; var $is_date = false; @@ -534,8 +535,10 @@ class WP_Query { } $now = gmdate('Y-m-d H:i:59'); - - if ($pagenow != 'post.php' && $pagenow != 'edit.php') { + + //only select past-dated posts, except if a logged in user is viewing a single: then, if they + //can edit the post, we let them through + if ($pagenow != 'post.php' && $pagenow != 'edit.php' && !($this->is_single && $user_ID)) { $where .= " AND post_date_gmt <= '$now'"; $distinct = 'DISTINCT'; } @@ -609,13 +612,23 @@ class WP_Query { } else { if ('draft' == $status) { // User must have edit permissions on the draft to preview. - if (! user_can_edit_post($user_ID, $this->posts[0]->ID)) + if (! user_can_edit_post($user_ID, $this->posts[0]->ID)) { $this->posts = array(); + } else { + $this->is_preview = true; + } } elseif ('private' == $status) { if ($this->posts[0]->post_author != $user_ID) $this->posts = array(); } } + } else { + if (mysql2date('U', $this->posts[0]->post_date) > mysql2date('U', $now)) { //it's future dated + $this->is_preview = true; + if (!current_user_can('edit_post', $this->posts[0]->ID)) { + $this->posts = array ( ); + } + } } } diff --git a/wp-includes/functions.php b/wp-includes/functions.php index 50458422d4..666d46192c 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -1404,6 +1404,12 @@ function is_subpost () { return $wp_query->is_subpost; } +function is_preview() { + global $wp_query; + + return $wp_query->is_preview; +} + function is_archive () { global $wp_query;