WordPress.org

Make WordPress Core

Ticket #17376: 17376.diff

File 17376.diff, 1.6 KB (added by Denis-de-Bernardy, 8 years ago)
  • wp-admin/admin.php

    diff --git a/wp-admin/admin.php b/wp-admin/admin.php
    index a617d11..8dd5690 100644
    a b if ( get_option('db_upgraded') ) { 
    7676
    7777require_once(ABSPATH . 'wp-admin/includes/admin.php');
    7878
     79if( is_multisite() ) {
     80        invalid_site_admin_redirect();
     81}
     82
    7983auth_redirect();
    8084
    8185// Schedule trash collection
  • wp-admin/includes/ms.php

    diff --git a/wp-admin/includes/ms.php b/wp-admin/includes/ms.php
    index f048417..baf9fbc 100644
    a b var tb_pathToImage = "../../wp-includes/js/thickbox/loadingAnimation.gif"; 
    811811</script>
    812812<?php
    813813}
     814
     815/**
     816 * Does a canonical redirect for the admin area.
     817 *
     818 * @since 3.9.0
     819 */
     820function invalid_site_admin_redirect() {
     821        global $current_blog;
     822
     823        // Redirect to the canonical admin URL if relevant
     824        if ( preg_match( '#(.*/wp-admin/)(.*)#', $_SERVER['REQUEST_URI'], $requested_admin_url )
     825                && trailingslashit( $requested_admin_url[1] ) !== parse_url( admin_url(), PHP_URL_PATH )
     826        ) {
     827                wp_redirect(
     828                        add_query_arg(
     829                                array( 'invalid_site_admin' => '1' ),
     830                                get_admin_url( $current_blog->blog_id, $requested_admin_url[2] )
     831                        )
     832                );
     833        }
     834
     835        if ( isset( $_GET['invalid_site_admin'] ) ) {
     836                // Display a notice on the page that was requested
     837                add_action( 'all_admin_notices', 'invalid_site_admin_redirect_notice' );
     838        }
     839
     840}
     841
     842/**
     843 * Adds a notice after a canonical redirect for the admin area.
     844 *
     845 * @since 3.9.0
     846 */
     847function invalid_site_admin_redirect_notice() {
     848        echo '<div class="error">' . __( 'You were redirected because the site whose admin area you were in does not exist.' ) . '</div>';
     849}