WordPress.org

Make WordPress Core

Ticket #17376: wp-17376.diff

File wp-17376.diff, 1.8 KB (added by ddean, 6 years ago)

proposal to handle the redirect and display an error message

  • wp-admin/admin.php

     
    6767
    6868nocache_headers();
    6969
     70if( is_multisite() ) {
     71        invalid_site_admin_redirect();
     72}
     73
    7074// Schedule trash collection
    7175if ( !wp_next_scheduled('wp_scheduled_delete') && !defined('WP_INSTALLING') )
    7276        wp_schedule_event(time(), 'daily', 'wp_scheduled_delete');
  • wp-admin/includes/ms.php

     
    742742        $count = get_blog_count();
    743743        return apply_filters( 'wp_is_large_network', $count > 10000, 'sites', $count );
    744744}
     745
     746function 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
     773function 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