WordPress.org

Make WordPress Core

Changeset 9509


Ignore:
Timestamp:
11/04/2008 01:00:12 PM (10 years ago)
Author:
azaozz
Message:

Preview fixes: different method of showing previews for published posts, now uses the proper templates. Fixes #8052

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/post.php

    r9499 r9509  
    999999 * @uses wp_create_post_autosave()
    10001000 *
    1001  * @return int|object the saved post id or wp_error object
     1001 * @return str URL to redirect to show the preview
    10021002 */
    10031003function post_preview() {
     
    10351035    }
    10361036
    1037     return $id;
     1037    if ( is_wp_error($id) )
     1038        wp_die( $id->get_error_message() );
     1039
     1040    if ( $_POST['post_status'] == 'draft'  ) {
     1041        $url = add_query_arg( 'preview', 'true', get_permalink($id) );
     1042    } else {
     1043        $nonce = wp_create_nonce('post_preview_' . $id);
     1044        $url = add_query_arg( array( 'preview' => 'true', 'preview_id' => $id, 'preview_nonce' => $nonce ), get_permalink($id) );
     1045    }
     1046
     1047    return $url;
    10381048}
    10391049
  • trunk/wp-admin/page.php

    r9473 r9509  
    177177    check_admin_referer( 'autosave', 'autosavenonce' );
    178178
    179     $id = post_preview();
    180 
    181     if ( is_wp_error($id) )
    182         wp_die( $id->get_error_message() );
    183 
    184     if ( $_POST['post_status'] == 'draft'  ) {
    185         $url = get_option('home') . '/?page_id=' . $id . '&preview=true';
    186     } else {
    187         $nonce = wp_create_nonce('post_preview_' . $id);
    188         $url = get_option('home') . '/?wp_preview=' . $id . '&preview_nonce=' . $nonce;
    189     }
     179    $url = post_preview();
    190180
    191181    wp_redirect($url);
  • trunk/wp-admin/post.php

    r9473 r9509  
    224224    check_admin_referer( 'autosave', 'autosavenonce' );
    225225
    226     $id = post_preview();
    227 
    228     if ( is_wp_error($id) )
    229         wp_die( $id->get_error_message() );
    230 
    231     if ( $_POST['post_status'] == 'draft'  ) {
    232         $url = get_option('home') . '/?p=' . $id . '&preview=true';
    233     } else {
    234         $nonce = wp_create_nonce('post_preview_' . $id);
    235         $url = get_option('home') . '/?wp_preview=' . $id . '&preview_nonce=' . $nonce;
    236     }
     226    $url = post_preview();
    237227
    238228    wp_redirect($url);
  • trunk/wp-includes/post.php

    r9452 r9509  
    35533553}
    35543554
     3555function _set_preview($post) {
     3556
     3557    if ( ! is_object($post) )
     3558        return $post;
     3559
     3560    $preview = wp_get_post_autosave($post->ID);
     3561
     3562    if ( ! is_object($preview) )
     3563        return $post;
     3564
     3565    $preview = sanitize_post($preview);
     3566
     3567    $post->post_content = $preview->post_content;
     3568    $post->post_title = $preview->post_title;
     3569    $post->post_excerpt = $preview->post_excerpt;
     3570
     3571    return $post;
     3572}
     3573
    35553574function _show_post_preview() {
    35563575
    3557     if ( isset($_GET['wp_preview']) && isset($_GET['preview_nonce']) ) {
    3558         $post_ID = (int) $_GET['wp_preview'];
    3559 
    3560         if ( false == wp_verify_nonce( $_GET['preview_nonce'], 'post_preview_' . $post_ID ) || ! current_user_can('edit_post', $post_ID) )
     3576    if ( isset($_GET['preview_id']) && isset($_GET['preview_nonce']) ) {
     3577        $id = (int) $_GET['preview_id'];
     3578
     3579        if ( false == wp_verify_nonce( $_GET['preview_nonce'], 'post_preview_' . $id ) )
    35613580            wp_die( __('You do not have permission to preview drafts.') );
    35623581
    3563         $q = array(
    3564             'name' => "{$post_ID}-autosave",
    3565             'post_parent' => $post_ID,
    3566             'post_type' => 'revision',
    3567             'post_status' => 'inherit'
    3568         );
    3569 
    3570         add_action( 'parse_query', '_wp_get_post_autosave_hack' );
    3571         query_posts($q);
    3572         remove_action( 'parse_query', '_wp_get_post_autosave_hack' );
    3573 
    3574     }
    3575 }
     3582        add_filter('the_preview', '_set_preview');
     3583    }
     3584}
  • trunk/wp-includes/query.php

    r9081 r9509  
    22952295                }
    22962296            }
     2297
     2298            if ( $this->is_preview && current_user_can( "edit_{$post_type}", $this->posts[0]->ID ) )
     2299                $this->posts[0] = apply_filters('the_preview', $this->posts[0]);
    22972300        }
    22982301
Note: See TracChangeset for help on using the changeset viewer.