Make WordPress Core


Ignore:
Timestamp:
09/08/2008 01:50:08 AM (18 years ago)
Author:
azaozz
Message:

Redirect to the correct URL on error, fixes #7706

File:
1 edited

Legend:

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

    r8742 r8843  
    3838 */
    3939function redirect_canonical($requested_url=null, $do_redirect=true) {
    40         global $wp_rewrite, $is_IIS;
     40        global $wp_rewrite, $is_IIS, $wp_query, $wpdb;
    4141
    4242        if ( is_feed() || is_trackback() || is_search() || is_comments_popup() || is_admin() || $is_IIS || ( isset($_POST) && count($_POST) ) || is_preview() || is_robots() )
     
    6060        $redirect_url = false;
    6161
     62        if ( is_singular() && 1 > $wp_query->post_count && ($id = get_query_var('p')) ) {
     63
     64                $vars = $wpdb->get_results( $wpdb->prepare("SELECT post_type, post_parent FROM $wpdb->posts WHERE ID = %d", $id) );
     65
     66                if ( isset($vars[0]) && $vars = $vars[0] ) {
     67                        if ( 'revision' == $vars->post_type && $vars->post_parent > 0 )
     68                                $id = $vars->post_parent;
     69
     70                        if ( $redirect_url = get_permalink($id) )
     71                                $redirect['query'] = remove_query_arg(array('p', 'page_id', 'attachment_id'), $redirect['query']);
     72                }
     73        }
     74
    6275        // These tests give us a WP-generated permalink
    6376        if ( is_404() ) {
     
    6578        } elseif ( is_object($wp_rewrite) && $wp_rewrite->using_permalinks() ) {
    6679                // rewriting of old ?p=X, ?m=2004, ?m=200401, ?m=20040101
    67                 if ( is_single() && isset($_GET['p']) ) {
     80                if ( is_single() && isset($_GET['p']) && ! $redirect_url ) {
    6881                        if ( $redirect_url = get_permalink(get_query_var('p')) )
    6982                                $redirect['query'] = remove_query_arg('p', $redirect['query']);
    70                 } elseif ( is_page() && isset($_GET['page_id']) ) {
     83                } elseif ( is_page() && isset($_GET['page_id']) && ! $redirect_url ) {
    7184                        if ( $redirect_url = get_permalink(get_query_var('page_id')) )
    7285                                $redirect['query'] = remove_query_arg('page_id', $redirect['query']);
     
    254267function redirect_guess_404_permalink() {
    255268        global $wpdb;
     269
    256270        if ( !get_query_var('name') )
    257271                return false;
Note: See TracChangeset for help on using the changeset viewer.