WordPress.org

Make WordPress Core

Ticket #13125: 13125.patch

File 13125.patch, 1.0 KB (added by solarissmoke, 4 years ago)

Redirect p=NNN requests to page_id=NNN when a page with that ID exists

  • canonical.php

     
    8282        // These tests give us a WP-generated permalink 
    8383        if ( is_404() ) { 
    8484                $redirect_url = redirect_guess_404_permalink(); 
     85                 
     86                // #13125: redirect p=NNN links to page_id=NNN (if page exists) instead of 404ing 
     87                if( $id = get_query_var('p') ) { 
     88                        $type = $wpdb->get_var( $wpdb->prepare("SELECT post_type FROM $wpdb->posts WHERE ID = %d", $id ) ); 
     89                        if($type && 'page' == $type) { 
     90                                $redirect['query'] = remove_query_arg(array('p', 'page_id'), $redirect['query']); 
     91                                $redirect_url = get_permalink($id); 
     92                        } 
     93                } 
    8594        } elseif ( is_object($wp_rewrite) && $wp_rewrite->using_permalinks() ) { 
    8695                // rewriting of old ?p=X, ?m=2004, ?m=200401, ?m=20040101 
    8796                if ( is_attachment() && !empty($_GET['attachment_id']) && ! $redirect_url ) { 
     
    387396 
    388397add_action('template_redirect', 'redirect_canonical'); 
    389398 
    390 ?> 
     399?> 
     400 No newline at end of file