Make WordPress Core

Ticket #20496: published-post-preview-canonical-redirect.patch

File published-post-preview-canonical-redirect.patch, 1.6 KB (added by amit, 12 years ago)
  • 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_admin() && get_query_var('preview') == 'true' && intval( get_query_var('p') ) > 0 && get_post_status( get_query_var('p') ) == 'publish' ) {
     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        }
     49
    4250        if ( is_trackback() || is_search() || is_comments_popup() || is_admin() || !empty($_POST) || is_preview() || is_robots() || ( $is_IIS && !iis7_supports_permalinks() ) )
    4351                return;
    4452
     
    6876        if ( !isset($redirect['query']) )
    6977                $redirect['query'] = '';
    7078
     79        // If its not a preview then remove it from URL
     80        if( ! is_preview() ) {
     81                $redirect['query'] = remove_query_arg( 'preview', $redirect['query'] );
     82        }
     83
    7184        if ( is_feed() && ( $id = get_query_var( 'p' ) ) ) {
    7285                if ( $redirect_url = get_post_comments_feed_link( $id, get_query_var( 'feed' ) ) ) {
    7386                        $redirect['query'] = _remove_qs_args_if_not_in_url( $redirect['query'], array( 'p', 'page_id', 'attachment_id', 'pagename', 'name', 'post_type', 'feed'), $redirect_url );