WordPress.org

Make WordPress Core

Ticket #17376: wp-17376-02.patch

File wp-17376-02.patch, 1.6 KB (added by ddean, 23 months ago)

Updated with nacin's simplified comparison and moved function call so it works on 3.6

  • wp-admin/admin.php

     
    6666 
    6767require_once(ABSPATH . 'wp-admin/includes/admin.php'); 
    6868 
     69if( is_multisite() ) { 
     70        invalid_site_admin_redirect(); 
     71} 
     72 
    6973auth_redirect(); 
    7074 
    7175// Schedule trash collection 
  • wp-admin/includes/ms.php

     
    675675</script> 
    676676<?php 
    677677} 
     678 
     679function invalid_site_admin_redirect() {  
     680          
     681        global $current_blog;  
     682          
     683        # Unless admin_url path matches base of current URL (up to wp-admin), redirect to canonical URL  
     684        if( preg_match( '/(.*\/wp-admin\/)(.*?)$/', $_SERVER['REQUEST_URI'], $requested_admin_url ) && 
     685                trailingslashit( $requested_admin_url[1] ) !== parse_url( admin_url(), PHP_URL_PATH ) ) { 
     686                 
     687                wp_redirect(   
     688                        add_query_arg( 
     689                                array( 'error' => 'invalid_site' ),   
     690                                get_admin_url( $current_blog->blog_id, $requested_admin_url[2] )  
     691                        ) 
     692                );  
     693        } 
     694          
     695        if( isset( $_GET['error'] ) && $_GET['error'] == 'invalid_site' ) {  
     696                        /** We have no idea what invalid page was requested, so fire this notice for all admin pages */  
     697                        add_action( 'all_admin_notices', 'invalid_site_admin_notice' );  
     698        }  
     699 
     700}  
     701 
     702function invalid_site_admin_notice() {  
     703        echo '<div class="update-nag">' . __('You were redirected here because you requested the dashboard for a site that does not exist.') . '</div>';  
     704} 
     705 No newline at end of file