Make WordPress Core

Ticket #20496: preview-patch.diff

File preview-patch.diff, 1.5 KB (added by joostdevalk, 11 years ago)

Improved patch

  • wp-includes/canonical.php

     
    3939function redirect_canonical( $requested_url = null, $do_redirect = true ) {
    4040        global $wp_rewrite, $is_IIS, $wp_query, $wpdb;
    4141
     42        // If we're not in wp-admin and the post has been published and preview nonce
     43        // is non-existant or invalid then no need for preview in query
     44        if ( is_preview() && get_query_var( 'p' ) && 'publish' == get_post_status( get_query_var( 'p' ) ) ) {
     45                if ( ! isset( $_GET['preview_id'] ) || ! isset( $_GET['preview_nonce'] ) || ! wp_verify_nonce( $_GET['preview_nonce'], 'post_preview_' . intval( $_GET['preview_id'] ) ) )
     46                        $wp_query->is_preview = false;
     47        }
     48
    4249        if ( is_trackback() || is_search() || is_comments_popup() || is_admin() || !empty($_POST) || is_preview() || is_robots() || ( $is_IIS && !iis7_supports_permalinks() ) )
    4350                return;
    4451
     
    6875        if ( !isset($redirect['query']) )
    6976                $redirect['query'] = '';
    7077
     78        // If its not a preview then remove it from URL
     79        if ( ! is_preview() )
     80                $redirect['query'] = remove_query_arg( 'preview', $redirect['query'] );
     81
    7182        if ( is_feed() && ( $id = get_query_var( 'p' ) ) ) {
    7283                if ( $redirect_url = get_post_comments_feed_link( $id, get_query_var( 'feed' ) ) ) {
    7384                        $redirect['query'] = _remove_qs_args_if_not_in_url( $redirect['query'], array( 'p', 'page_id', 'attachment_id', 'pagename', 'name', 'post_type', 'feed'), $redirect_url );