Make WordPress Core

Changeset 28874


Ignore:
Timestamp:
06/28/2014 02:12:19 AM (8 years ago)
Author:
wonderboymusic
Message:

Perform a canonical redirect for posts that are published but are visited at a ?p=123&preview=true URL.

Props amit, joostdevalk.
Fixes #20496.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/canonical.php

    r28712 r28874  
    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'] )
     46            || ! isset( $_GET['preview_nonce'] )
     47            || ! wp_verify_nonce( $_GET['preview_nonce'], 'post_preview_' . (int) $_GET['preview_id'] ) ) {
     48            $wp_query->is_preview = false;
     49        }
     50    }
     51
    4252    if ( is_trackback() || is_search() || is_comments_popup() || is_admin() || !empty($_POST) || is_preview() || is_robots() || ( $is_IIS && !iis7_supports_permalinks() ) )
    4353        return;
     
    6878    if ( !isset($redirect['query']) )
    6979        $redirect['query'] = '';
     80
     81    // If its not a preview then remove it from URL
     82    if ( ! is_preview() ) {
     83        $redirect['query'] = remove_query_arg( 'preview', $redirect['query'] );
     84    }
    7085
    7186    if ( is_feed() && ( $id = get_query_var( 'p' ) ) ) {
Note: See TracChangeset for help on using the changeset viewer.