WordPress.org

Make WordPress Core


Ignore:
Timestamp:
10/07/2010 07:34:18 PM (10 years ago)
Author:
ryan
Message:

First pass of user admin. Network admin and screen cleanups. see #14696

File:
1 edited

Legend:

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

    r15678 r15746  
    6060 * @since MU 1.0
    6161 * @uses get_blogs_of_user()
    62  * @uses get_dashboard_blog()
    6362 * @uses add_user_to_blog()
    6463 * @uses update_user_meta()
     
    7372    global $wpdb;
    7473    $blogs = get_blogs_of_user( $user_id );
    75     if ( empty( $blogs ) ) {
    76         $details = get_dashboard_blog();
    77         add_user_to_blog( $details->blog_id, $user_id, 'subscriber' );
    78         update_user_meta( $user_id, 'primary_blog', $details->blog_id );
    79         wp_cache_delete( $user_id, 'users' );
    80         return $details;
    81     }
     74    if ( empty( $blogs ) )
     75        return null;
     76
     77    if ( !is_multisite() )
     78        return $blogs[$wpdb->blogid];
    8279
    8380    $primary_blog = get_user_meta( $user_id, 'primary_blog', true );
    84     $details = get_dashboard_blog();
     81    $first_blog = current($blogs);
    8582    if ( $primary_blog ) {
    86         if ( isset( $blogs[ $primary_blog ] ) == false ) {
    87             add_user_to_blog( $details->blog_id, $user_id, 'subscriber' );
    88             update_user_meta( $user_id, 'primary_blog', $details->blog_id );
    89             wp_cache_delete( $user_id, 'users' );
     83        if ( ! isset( $blogs[ $primary_blog ] ) ) {
     84            add_user_to_blog( $first_blog->blog_id, $user_id, 'subscriber' );
     85            update_user_meta( $user_id, 'primary_blog', $first_blog->blog_id );
     86            $primary = $first_blog;
    9087        } else {
    91             $details = get_blog_details( $primary_blog );
     88            $primary = get_blog_details( $primary_blog );
    9289        }
    9390    } else {
    94         add_user_to_blog( $details->blog_id, $user_id, 'subscriber' ); // Add subscriber permission for dashboard blog
    95         update_user_meta( $user_id, 'primary_blog', $details->blog_id );
    96     }
    97 
    98     if ( ( is_object( $details ) == false ) || ( is_object( $details ) && $details->archived == 1 || $details->spam == 1 || $details->deleted == 1 ) ) {
     91        add_user_to_blog( $first_blog->blog_id, $user_id, 'subscriber' );
     92        update_user_meta( $user_id, 'primary_blog', $first_blog->blog_id );
     93        $primary = $first_blog;
     94    }
     95
     96    if ( ( ! is_object( $primary ) ) || ( is_object( $primary ) && $primary->archived == 1 || $primary->spam == 1 || $primary->deleted == 1 ) ) {
    9997        $blogs = get_blogs_of_user( $user_id, true ); // if a user's primary blog is shut down, check their other blogs.
    10098        $ret = false;
     
    106104                if ( is_object( $details ) && $details->archived == 0 && $details->spam == 0 && $details->deleted == 0 ) {
    107105                    $ret = $blog;
    108                     $changed = false;
    109                     if ( get_user_meta( $user_id , 'primary_blog', true ) != $blog_id ) {
     106                    if ( get_user_meta( $user_id , 'primary_blog', true ) != $blog_id )
    110107                        update_user_meta( $user_id, 'primary_blog', $blog_id );
    111                         $changed = true;
    112                     }
    113                     if ( !get_user_meta($user_id , 'source_domain', true) ) {
     108                    if ( !get_user_meta($user_id , 'source_domain', true) )
    114109                        update_user_meta( $user_id, 'source_domain', $blog->domain );
    115                         $changed = true;
    116                     }
    117                     if ( $changed )
    118                         wp_cache_delete( $user_id, 'users' );
    119110                    break;
    120111                }
    121112            }
    122113        } else {
    123             // Should never get here
    124             $dashboard_blog = get_dashboard_blog();
    125             add_user_to_blog( $dashboard_blog->blog_id, $user_id, 'subscriber' ); // Add subscriber permission for dashboard blog
    126             update_user_meta( $user_id, 'primary_blog', $dashboard_blog->blog_id );
    127             return $dashboard_blog;
     114            return null;
    128115        }
    129116        return $ret;
    130117    } else {
    131         return $details;
     118        return $primary;
    132119    }
    133120}
     
    841828
    842829        wpmu_welcome_user_notification($user_id, $password, $meta);
    843         $user_site = get_site_option( 'dashboard_blog', $current_site->blog_id );
    844 
    845         if ( $user_site == false )
    846             add_user_to_blog( '1', $user_id, get_site_option( 'default_user_role', 'subscriber' ) );
    847         else
    848             add_user_to_blog( $user_site, $user_id, get_site_option( 'default_user_role', 'subscriber' ) );
    849830
    850831        add_new_user_to_blog( $user_id, $user_email, $meta );
     
    927908    update_option( 'blog_public', (int)$meta['public'] );
    928909
    929     if ( !is_super_admin() && get_user_meta( $user_id, 'primary_blog', true ) == get_site_option( 'dashboard_blog', 1 ) )
     910    if ( !is_super_admin() && ! get_user_meta( $user_id, 'primary_blog', true ) )
    930911        update_user_meta( $user_id, 'primary_blog', $blog_id );
    931912
     
    14611442add_action('update_option_blog_public', 'update_blog_public', 10, 2);
    14621443
    1463 /* Redirect all hits to "dashboard" blog to wp-admin/ Dashboard. */
    1464 function redirect_mu_dashboard() {
    1465     global $current_site, $current_blog;
    1466 
    1467     $dashboard_blog = get_dashboard_blog();
    1468     if ( $current_blog->blog_id == $dashboard_blog->blog_id && $dashboard_blog->blog_id != $current_site->blog_id ) {
    1469         $protocol = ( is_ssl() ? 'https://' : 'http://' );
    1470         wp_redirect( $protocol . $dashboard_blog->domain . trailingslashit( $dashboard_blog->path ) . 'wp-admin/' );
    1471         die();
    1472     }
    1473 }
    1474 add_action( 'template_redirect', 'redirect_mu_dashboard' );
    1475 
    14761444function get_dashboard_blog() {
    14771445    if ( $blog = get_site_option( 'dashboard_blog' ) )
Note: See TracChangeset for help on using the changeset viewer.