Preview fixes: different method of showing previews for published posts, now uses the proper templates. Fixes #8052
git-svn-id: http://svn.automattic.com/wordpress/trunk@9509 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
8c67165a93
commit
7c063b0b50
|
@ -998,7 +998,7 @@ function wp_create_post_autosave( $post_id ) {
|
|||
* @uses current_user_can()
|
||||
* @uses wp_create_post_autosave()
|
||||
*
|
||||
* @return int|object the saved post id or wp_error object
|
||||
* @return str URL to redirect to show the preview
|
||||
*/
|
||||
function post_preview() {
|
||||
|
||||
|
@ -1034,7 +1034,17 @@ function post_preview() {
|
|||
$id = $post->ID;
|
||||
}
|
||||
|
||||
return $id;
|
||||
if ( is_wp_error($id) )
|
||||
wp_die( $id->get_error_message() );
|
||||
|
||||
if ( $_POST['post_status'] == 'draft' ) {
|
||||
$url = add_query_arg( 'preview', 'true', get_permalink($id) );
|
||||
} else {
|
||||
$nonce = wp_create_nonce('post_preview_' . $id);
|
||||
$url = add_query_arg( array( 'preview' => 'true', 'preview_id' => $id, 'preview_nonce' => $nonce ), get_permalink($id) );
|
||||
}
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -176,17 +176,7 @@ case 'delete':
|
|||
case 'preview':
|
||||
check_admin_referer( 'autosave', 'autosavenonce' );
|
||||
|
||||
$id = post_preview();
|
||||
|
||||
if ( is_wp_error($id) )
|
||||
wp_die( $id->get_error_message() );
|
||||
|
||||
if ( $_POST['post_status'] == 'draft' ) {
|
||||
$url = get_option('home') . '/?page_id=' . $id . '&preview=true';
|
||||
} else {
|
||||
$nonce = wp_create_nonce('post_preview_' . $id);
|
||||
$url = get_option('home') . '/?wp_preview=' . $id . '&preview_nonce=' . $nonce;
|
||||
}
|
||||
$url = post_preview();
|
||||
|
||||
wp_redirect($url);
|
||||
exit();
|
||||
|
|
|
@ -223,17 +223,7 @@ case 'delete':
|
|||
case 'preview':
|
||||
check_admin_referer( 'autosave', 'autosavenonce' );
|
||||
|
||||
$id = post_preview();
|
||||
|
||||
if ( is_wp_error($id) )
|
||||
wp_die( $id->get_error_message() );
|
||||
|
||||
if ( $_POST['post_status'] == 'draft' ) {
|
||||
$url = get_option('home') . '/?p=' . $id . '&preview=true';
|
||||
} else {
|
||||
$nonce = wp_create_nonce('post_preview_' . $id);
|
||||
$url = get_option('home') . '/?wp_preview=' . $id . '&preview_nonce=' . $nonce;
|
||||
}
|
||||
$url = post_preview();
|
||||
|
||||
wp_redirect($url);
|
||||
exit();
|
||||
|
|
|
@ -3552,24 +3552,33 @@ function wp_get_post_revisions( $post_id = 0, $args = null ) {
|
|||
return $revisions;
|
||||
}
|
||||
|
||||
function _set_preview($post) {
|
||||
|
||||
if ( ! is_object($post) )
|
||||
return $post;
|
||||
|
||||
$preview = wp_get_post_autosave($post->ID);
|
||||
|
||||
if ( ! is_object($preview) )
|
||||
return $post;
|
||||
|
||||
$preview = sanitize_post($preview);
|
||||
|
||||
$post->post_content = $preview->post_content;
|
||||
$post->post_title = $preview->post_title;
|
||||
$post->post_excerpt = $preview->post_excerpt;
|
||||
|
||||
return $post;
|
||||
}
|
||||
|
||||
function _show_post_preview() {
|
||||
|
||||
if ( isset($_GET['wp_preview']) && isset($_GET['preview_nonce']) ) {
|
||||
$post_ID = (int) $_GET['wp_preview'];
|
||||
if ( isset($_GET['preview_id']) && isset($_GET['preview_nonce']) ) {
|
||||
$id = (int) $_GET['preview_id'];
|
||||
|
||||
if ( false == wp_verify_nonce( $_GET['preview_nonce'], 'post_preview_' . $post_ID ) || ! current_user_can('edit_post', $post_ID) )
|
||||
if ( false == wp_verify_nonce( $_GET['preview_nonce'], 'post_preview_' . $id ) )
|
||||
wp_die( __('You do not have permission to preview drafts.') );
|
||||
|
||||
$q = array(
|
||||
'name' => "{$post_ID}-autosave",
|
||||
'post_parent' => $post_ID,
|
||||
'post_type' => 'revision',
|
||||
'post_status' => 'inherit'
|
||||
);
|
||||
|
||||
add_action( 'parse_query', '_wp_get_post_autosave_hack' );
|
||||
query_posts($q);
|
||||
remove_action( 'parse_query', '_wp_get_post_autosave_hack' );
|
||||
|
||||
add_filter('the_preview', '_set_preview');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2294,6 +2294,9 @@ class WP_Query {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( $this->is_preview && current_user_can( "edit_{$post_type}", $this->posts[0]->ID ) )
|
||||
$this->posts[0] = apply_filters('the_preview', $this->posts[0]);
|
||||
}
|
||||
|
||||
// Put sticky posts at the top of the posts array
|
||||
|
|
Loading…
Reference in New Issue