Make WordPress Core

Changeset 19880


Ignore:
Timestamp:
02/08/2012 08:11:52 PM (13 years ago)
Author:
nacin
Message:

In case of 404, redirect /login, /dashboard, /admin to corresponding WP equivalents. fixes #19607.

File:
1 edited

Legend:

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

    r19878 r19880  
    9191                $redirect['query'] = remove_query_arg(array('p', 'page_id', 'attachment_id', 'post_type'), $redirect['query']);
    9292            }
    93         }
    94 
    95         if ( ! $redirect_url && get_option( 'home' ) != get_option( 'siteurl' ) ) {
    96             if ( trailingslashit( $original['path'] ) == home_url( 'wp-admin/', 'relative' ) )
    97                 $redirect_url = admin_url();
    98             elseif ( $original['path'] == home_url( 'wp-login.php', 'relative' ) )
    99                 $redirect_url = site_url( 'wp-login.php', 'login' );
    10093        }
    10194
     
    473466
    474467add_action('template_redirect', 'redirect_canonical');
     468
     469function wp_redirect_admin_locations() {
     470    global $wp_rewrite;
     471    if ( ! ( is_404() && $wp_rewrite->using_permalinks() ) )
     472        return;
     473
     474    $admins = array(
     475        home_url( 'wp-admin', 'relative' ),
     476        home_url( 'dashboard', 'relative' ),
     477        home_url( 'admin', 'relative' ),
     478        site_url( 'dashboard', 'relative' ),
     479        site_url( 'admin', 'relative' ),
     480    );
     481    if ( in_array( untrailingslashit( $_SERVER['REQUEST_URI'] ), $admins ) ) {
     482        wp_redirect( admin_url() );
     483        exit;
     484    }
     485
     486    $logins = array(
     487        home_url( 'wp-login.php', 'relative' ),
     488        home_url( 'login', 'relative' ),
     489        site_url( 'login', 'relative' ),
     490    );
     491    if ( in_array( untrailingslashit( $_SERVER['REQUEST_URI'] ), $logins ) ) {
     492        wp_redirect( site_url( 'wp-login.php', 'login' ) );
     493        exit;
     494    }
     495}
     496
     497add_action( 'template_redirect', 'wp_redirect_admin_locations', 1000 );
Note: See TracChangeset for help on using the changeset viewer.