WordPress.org

Make WordPress Core

Changeset 17762


Ignore:
Timestamp:
04/29/2011 12:43:48 AM (7 years ago)
Author:
ryan
Message:

Show access denied page and list a user's sites if they visit an admin they don't have permissions for rather than redirecting to the users' primary blog. fixes #17121

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/ms.php

    r17228 r17762  
    497497add_filter( 'get_term', 'sync_category_tag_slugs', 10, 2 );
    498498
    499 function redirect_user_to_blog() {
    500     $c = 0;
    501     if ( isset( $_GET['c'] ) )
    502         $c = (int) $_GET['c'];
    503 
    504     if ( $c >= 5 ) {
    505         wp_die( __( "You don’t have permission to view this site. Please contact the system administrator." ) );
    506     }
    507     $c ++;
    508 
    509     $blog = get_active_blog_for_user( get_current_user_id() );
    510 
    511     if ( is_object( $blog ) ) {
    512         wp_redirect( get_admin_url( $blog->blog_id, '?c=' . $c ) ); // redirect and count to 5, "just in case"
    513     } else {
    514         wp_redirect( user_admin_url( '?c=' . $c ) ); // redirect and count to 5, "just in case"
    515     }
     499function _access_denied_splash() {
     500    if ( ! is_user_logged_in() )
     501        return;
     502
     503    $blogs = get_blogs_of_user( get_current_user_id() );
     504
     505    $blog_name = get_bloginfo( 'name' );
     506
     507    if ( empty( $blogs ) ) {
     508        wp_die( sprintf( __( 'You attempted to access the "%s" dashboard, but you do not currently have privileges on this site. If you believe you should be able to access the "Test" dashboard, please contact your network administrator.' ), $blog_name ) );
     509        exit;
     510    }
     511
     512    $output = '<p>' . sprintf( __( 'You attempted to access the "%s" dashboard, but you do not currently have privileges on this site. If you believe you should be able to access the "Test" dashboard, please contact your network administrator.' ), $blog_name ) . '</p>';
     513    $output .= '<p>' . __( 'If you reached this screen by accident and meant to visit one your own sites, here are some shortcuts to help you find your way.' ) . '</p>';
     514
     515    $output .= '<h3>' . __('Your Sites') . '</h3>';
     516    $output .= '<table>';
     517
     518    foreach ( $blogs as $blog ) {
     519        $output .= "<tr>";
     520        $output .= "<td valign='top'>";
     521        $output .= "{$blog->blogname}";
     522        $output .= "</td>";
     523        $output .= "<td valign='top'>";
     524        $output .= "<a href='" . esc_url( get_admin_url( $blog->userblog_id ) ) . "'>" . __( 'Visit Dashboard' ) . "</a> | <a href='" . esc_url( get_home_url( $blog->userblog_id ) ). "'>" . __( 'View Site' ) . "</a>" ;
     525        $output .= "</td>";
     526        $output .= "</tr>";
     527    }
     528    $output .= '</table>';
     529
     530    wp_die( $output );
    516531    exit;
    517532}
    518 add_action( 'admin_page_access_denied', 'redirect_user_to_blog', 99 );
     533add_action( 'admin_page_access_denied', '_access_denied_splash', 99 );
    519534
    520535function check_import_new_users( $permission ) {
Note: See TracChangeset for help on using the changeset viewer.