| 745 | |
| 746 | function invalid_site_admin_redirect() { |
| 747 | |
| 748 | global $current_blog; |
| 749 | |
| 750 | # Unless admin_url (minus hostname) matches base of current URL (up to wp-admin), redirect to canonical URL |
| 751 | if( preg_match( '|^http(s?)\://([^/]+)/(([^/]+/)*)wp-admin|', get_admin_url(), $canon_uri_match ) && |
| 752 | preg_match( '|^/(([^/]+/)*)wp-admin/(.*?)$|', $_SERVER['REQUEST_URI'], $requested_uri_match ) ) { |
| 753 | |
| 754 | if( $canon_uri_match[3] != $requested_uri_match[1] ) { |
| 755 | |
| 756 | wp_redirect( |
| 757 | add_query_arg( |
| 758 | array( 'error' => 'invalid_site' ), |
| 759 | get_admin_url($current_blog->blog_id, $requested_uri_match[3]) |
| 760 | ) |
| 761 | ); |
| 762 | |
| 763 | } |
| 764 | } |
| 765 | |
| 766 | if( isset( $_GET['error'] ) && $_GET['error'] == 'invalid_site' ) { |
| 767 | /** We have no idea what invalid page was requested, so fire this notice for all admin pages */ |
| 768 | add_action( 'all_admin_notices', 'invalid_site_admin_notice' ); |
| 769 | } |
| 770 | |
| 771 | } |
| 772 | |
| 773 | function invalid_site_admin_notice() { |
| 774 | echo '<div class="update-nag">' . __('You were redirected here because you requested the dashboard for a site that does not exist.') . '</div>'; |
| 775 | } |
| 776 | |