Make WordPress Core


Ignore:
File:
1 edited

Legend:

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

    r17379 r15452  
    88 */
    99
    10 /**
    11  * Gets the network's site and user counts.
    12  *
    13  * @since MU 1.0
    14  * @uses get_blog_count()
    15  * @uses get_user_count()
    16  *
    17  * @return array Site and user count for the network.
    18  */
    1910function get_sitestats() {
    2011    global $wpdb;
    2112
    2213    $stats['blogs'] = get_blog_count();
    23     $stats['users'] = get_user_count();
    24 
     14
     15    $count_ts = get_site_option( 'user_count_ts' );
     16    if ( time() - $count_ts > 3600 ) {
     17        $count = $wpdb->get_var( "SELECT COUNT(ID) FROM $wpdb->users" );
     18        update_site_option( 'user_count', $count );
     19        update_site_option( 'user_count_ts', time() );
     20    } else {
     21        $count = get_site_option( 'user_count' );
     22    }
     23    $stats['users'] = $count;
    2524    return $stats;
    2625}
    2726
    28 /**
    29  * Get the admin for a domain/path combination.
    30  *
    31  * @since MU 1.0
    32  *
    33  * @param string $sitedomain Optional. Site domain.
    34  * @param string $path Optional. Site path.
    35  * @return array The network admins
    36  */
    3727function get_admin_users_for_domain( $sitedomain = '', $path = '' ) {
    3828    global $wpdb;
     
    4939}
    5040
    51 /**
    52  * Get one of a user's active blogs
    53  *
    54  * Returns the user's primary blog, if she has one and
    55  * it is active. If it's inactive, function returns another
    56  * active blog of the user. If none are found, the user
    57  * is added as a Subscriber to the Dashboard Blog and that blog
    58  * is returned.
    59  *
    60  * @since MU 1.0
    61  * @uses get_blogs_of_user()
    62  * @uses add_user_to_blog()
    63  * @uses get_blog_details()
    64  *
    65  * @param int $user_id The unique ID of the user
    66  * @return object The blog object
    67  */
    68 function get_active_blog_for_user( $user_id ) {
     41function get_blogs_of_user( $id, $all = false ) {
     42    global $wpdb;
     43
     44    $cache_suffix = $all ? '_all' : '_short';
     45    $return = wp_cache_get( 'blogs_of_user_' . $id . $cache_suffix, 'users' );
     46    if ( $return )
     47        return apply_filters( 'get_blogs_of_user', $return, $id, $all );
     48
     49    $user = get_userdata( (int) $id );
     50    if ( !$user )
     51        return false;
     52
     53    $blogs = $match = array();
     54    $prefix_length = strlen($wpdb->base_prefix);
     55    foreach ( (array) $user as $key => $value ) {
     56        if ( $prefix_length && substr($key, 0, $prefix_length) != $wpdb->base_prefix )
     57            continue;
     58        if ( substr($key, -12, 12) != 'capabilities' )
     59            continue;
     60        if ( preg_match( '/^' . $wpdb->base_prefix . '((\d+)_)?capabilities$/', $key, $match ) ) {
     61            if ( count( $match ) > 2 )
     62                $blog_id = $match[ 2 ];
     63            else
     64                $blog_id = 1;
     65            $blog = get_blog_details( $blog_id );
     66            if ( $blog && isset( $blog->domain ) && ( $all == true || $all == false && ( $blog->archived == 0 && $blog->spam == 0 && $blog->deleted == 0 ) ) ) {
     67                $blogs[ $blog_id ]->userblog_id = $blog_id;
     68                $blogs[ $blog_id ]->blogname        = $blog->blogname;
     69                $blogs[ $blog_id ]->domain      = $blog->domain;
     70                $blogs[ $blog_id ]->path            = $blog->path;
     71                $blogs[ $blog_id ]->site_id     = $blog->site_id;
     72                $blogs[ $blog_id ]->siteurl     = $blog->siteurl;
     73            }
     74        }
     75    }
     76
     77    wp_cache_add( 'blogs_of_user_' . $id . $cache_suffix, $blogs, 'users', 5 );
     78    return apply_filters( 'get_blogs_of_user', $blogs, $id, $all );
     79}
     80
     81function get_active_blog_for_user( $user_id ) { // get an active blog for user - either primary blog or from blogs list
    6982    global $wpdb;
    7083    $blogs = get_blogs_of_user( $user_id );
    71     if ( empty( $blogs ) )
    72         return null;
    73 
    74     if ( !is_multisite() )
    75         return $blogs[$wpdb->blogid];
     84    if ( empty( $blogs ) ) {
     85        $details = get_dashboard_blog();
     86        add_user_to_blog( $details->blog_id, $user_id, 'subscriber' );
     87        update_user_meta( $user_id, 'primary_blog', $details->blog_id );
     88        wp_cache_delete( $user_id, 'users' );
     89        return $details;
     90    }
    7691
    7792    $primary_blog = get_user_meta( $user_id, 'primary_blog', true );
    78     $first_blog = current($blogs);
    79     if ( false !== $primary_blog ) {
    80         if ( ! isset( $blogs[ $primary_blog ] ) ) {
    81             update_user_meta( $user_id, 'primary_blog', $first_blog->userblog_id );
    82             $primary = $first_blog;
     93    $details = get_dashboard_blog();
     94    if ( $primary_blog ) {
     95        $blogs = get_blogs_of_user( $user_id );
     96        if ( isset( $blogs[ $primary_blog ] ) == false ) {
     97            add_user_to_blog( $details->blog_id, $user_id, 'subscriber' );
     98            update_user_meta( $user_id, 'primary_blog', $details->blog_id );
     99            wp_cache_delete( $user_id, 'users' );
    83100        } else {
    84             $primary = get_blog_details( $primary_blog );
     101            $details = get_blog_details( $primary_blog );
    85102        }
    86103    } else {
    87         //TODO Review this call to add_user_to_blog too - to get here the user must have a role on this blog?
    88         add_user_to_blog( $first_blog->userblog_id, $user_id, 'subscriber' );
    89         update_user_meta( $user_id, 'primary_blog', $first_blog->userblog_id );
    90         $primary = $first_blog;
    91     }
    92 
    93     if ( ( ! is_object( $primary ) ) || ( is_object( $primary ) && $primary->archived == 1 || $primary->spam == 1 || $primary->deleted == 1 ) ) {
     104        add_user_to_blog( $details->blog_id, $user_id, 'subscriber' ); // Add subscriber permission for dashboard blog
     105        update_user_meta( $user_id, 'primary_blog', $details->blog_id );
     106    }
     107
     108    if ( ( is_object( $details ) == false ) || ( is_object( $details ) && $details->archived == 1 || $details->spam == 1 || $details->deleted == 1 ) ) {
    94109        $blogs = get_blogs_of_user( $user_id, true ); // if a user's primary blog is shut down, check their other blogs.
    95110        $ret = false;
     
    101116                if ( is_object( $details ) && $details->archived == 0 && $details->spam == 0 && $details->deleted == 0 ) {
    102117                    $ret = $blog;
    103                     if ( get_user_meta( $user_id , 'primary_blog', true ) != $blog_id )
     118                    $changed = false;
     119                    if ( get_user_meta( $user_id , 'primary_blog', true ) != $blog_id ) {
    104120                        update_user_meta( $user_id, 'primary_blog', $blog_id );
    105                     if ( !get_user_meta($user_id , 'source_domain', true) )
     121                        $changed = true;
     122                    }
     123                    if ( !get_user_meta($user_id , 'source_domain', true) ) {
    106124                        update_user_meta( $user_id, 'source_domain', $blog->domain );
     125                        $changed = true;
     126                    }
     127                    if ( $changed )
     128                        wp_cache_delete( $user_id, 'users' );
    107129                    break;
    108130                }
    109131            }
    110132        } else {
    111             return null;
     133            // Should never get here
     134            $dashboard_blog = get_dashboard_blog();
     135            add_user_to_blog( $dashboard_blog->blog_id, $user_id, 'subscriber' ); // Add subscriber permission for dashboard blog
     136            update_user_meta( $user_id, 'primary_blog', $dashboard_blog->blog_id );
     137            return $dashboard_blog;
    112138        }
    113139        return $ret;
    114140    } else {
    115         return $primary;
    116     }
    117 }
    118 
    119 /**
    120  * Find out whether a user is a member of a given blog.
    121  *
    122  * @since MU 1.1
    123  * @uses get_blogs_of_user()
    124  *
    125  * @param int $user_id The unique ID of the user
    126  * @param int $blog Optional. If no blog_id is provided, current site is used
    127  * @return bool
    128  */
     141        return $details;
     142    }
     143}
     144
    129145function is_user_member_of_blog( $user_id, $blog_id = 0 ) {
    130146    $user_id = (int) $user_id;
     
    143159}
    144160
    145 /**
    146  * The number of active users in your installation.
    147  *
    148  * The count is cached and updated twice daily. This is not a live count.
    149  *
    150  * @since MU 2.7
    151  *
    152  * @return int
    153  */
    154161function get_user_count() {
    155     return get_site_option( 'user_count' );
    156 }
    157 
    158 /**
    159  * The number of active sites on your installation.
    160  *
    161  * The count is cached and updated twice daily. This is not a live count.
    162  *
    163  * @since MU 1.0
    164  *
    165  * @param int $id Optional. A site_id.
    166  * @return int
    167  */
     162    global $wpdb;
     163
     164    $count_ts = get_site_option( 'user_count_ts' );
     165    if ( time() - $count_ts > 3600 ) {
     166        $count = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(ID) as c FROM $wpdb->users WHERE spam = '0' AND deleted = '0'") );
     167        update_site_option( 'user_count', $count );
     168        update_site_option( 'user_count_ts', time() );
     169    }
     170
     171    $count = get_site_option( 'user_count' );
     172
     173    return $count;
     174}
     175
    168176function get_blog_count( $id = 0 ) {
    169     return get_site_option( 'blog_count' );
    170 }
    171 
    172 /**
    173  * Get a blog post from any site on the network.
    174  *
    175  * @since MU 1.0
    176  *
    177  * @param int $blog_id ID of the blog.
    178  * @param int $post_id ID of the post you're looking for.
    179  * @return object The post.
    180  */
     177    global $wpdb;
     178
     179    if ( $id == 0 )
     180        $id = $wpdb->siteid;
     181
     182    $count_ts = get_site_option( 'blog_count_ts' );
     183    if ( time() - $count_ts > 3600 ) {
     184        $count = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(blog_id) as c FROM $wpdb->blogs WHERE site_id = %d AND spam = '0' AND deleted = '0' and archived = '0'", $id) );
     185        update_site_option( 'blog_count', $count );
     186        update_site_option( 'blog_count_ts', time() );
     187    }
     188
     189    $count = get_site_option( 'blog_count' );
     190
     191    return $count;
     192}
     193
    181194function get_blog_post( $blog_id, $post_id ) {
    182195    global $wpdb;
     
    192205}
    193206
    194 /**
    195  * Add a user to a blog.
    196  *
    197  * Use the 'add_user_to_blog' action to fire an event when
    198  * users are added to a blog.
    199  *
    200  * @since MU 1.0
    201  *
    202  * @param int $blog_id ID of the blog you're adding the user to.
    203  * @param int $user_id ID of the user you're adding.
    204  * @param string $role The role you want the user to have
    205  * @return bool
    206  */
    207207function add_user_to_blog( $blog_id, $user_id, $role ) {
    208208    switch_to_blog($blog_id);
     
    210210    $user = new WP_User($user_id);
    211211
    212     if ( empty( $user->ID ) ) {
    213         restore_current_blog();
     212    if ( empty( $user->ID ) )
    214213        return new WP_Error('user_does_not_exist', __('That user does not exist.'));
    215     }
    216214
    217215    if ( !get_user_meta($user_id, 'primary_blog', true) ) {
     
    229227}
    230228
    231 /**
    232  * Remove a user from a blog.
    233  *
    234  * Use the 'remove_user_from_blog' action to fire an event when
    235  * users are removed from a blog.
    236  *
    237  * Accepts an optional $reassign parameter, if you want to
    238  * reassign the user's blog posts to another user upon removal.
    239  *
    240  * @since MU 1.0
    241  *
    242  * @param int $user_id ID of the user you're removing.
    243  * @param int $blog_id ID of the blog you're removing the user from.
    244  * @param string $reassign Optional. A user to whom to reassign posts.
    245  * @return bool
    246  */
    247229function remove_user_from_blog($user_id, $blog_id = '', $reassign = '') {
    248230    global $wpdb;
     
    272254    // wp_revoke_user($user_id);
    273255    $user = new WP_User($user_id);
    274     if ( empty( $user->ID ) ) {
    275         restore_current_blog();
     256    if ( empty( $user->ID ) )
    276257        return new WP_Error('user_does_not_exist', __('That user does not exist.'));
    277     }
    278258
    279259    $user->remove_all_caps();
     
    294274}
    295275
    296 /**
    297  * Create an empty blog.
    298  *
    299  * @since MU 1.0
    300  * @uses install_blog()
    301  *
    302  * @param string $domain The new blog's domain.
    303  * @param string $path The new blog's path.
    304  * @param string $string The new blog's title.
    305  * @param int $site Optional. Defaults to 1.
    306  * @return int The ID of the newly created blog
    307  */
    308276function create_empty_blog( $domain, $path, $weblog_title, $site_id = 1 ) {
    309277    $domain         = addslashes( $domain );
     
    317285        return __( 'Error: Site URL already taken.' );
    318286
    319     // Need to back up wpdb table names, and create a new wp_blogs entry for new blog.
     287    // Need to backup wpdb table names, and create a new wp_blogs entry for new blog.
    320288    // Need to get blog_id from wp_blogs, and create new table names.
    321289    // Must restore table names at the end of function.
     
    331299}
    332300
    333 /**
    334  * Get the permalink for a post on another blog.
    335  *
    336  * @since MU 1.0
    337  *
    338  * @param int $_blog_id ID of the source blog.
    339  * @param int $post_id ID of the desired post.
    340  * @return string The post's permalink
    341  */
    342301function get_blog_permalink( $_blog_id, $post_id ) {
    343302    $key = "{$_blog_id}-{$post_id}-blog_permalink";
     
    352311}
    353312
    354 /**
    355  * Get a blog's numeric ID from its URL.
    356  *
    357  * On a subdirectory installation like example.com/blog1/,
    358  * $domain will be the root 'example.com' and $path the
    359  * subdirectory '/blog1/'. With subdomains like blog1.example.com,
    360  * $domain is 'blog1.example.com' and $path is '/'.
    361  *
    362  * @since MU 2.6.5
    363  *
    364  * @param string $domain
    365  * @param string $path Optional. Not required for subdomain installations.
    366  * @return int
    367  */
    368313function get_blog_id_from_url( $domain, $path = '/' ) {
    369314    global $wpdb;
     
    390335}
    391336
    392 // Admin functions
    393 
    394 /**
    395  * Redirect a user based on $_GET or $_POST arguments.
    396  *
    397  * The function looks for redirect arguments in the following order:
    398  * 1) $_GET['ref']
    399  * 2) $_POST['ref']
    400  * 3) $_SERVER['HTTP_REFERER']
    401  * 4) $_GET['redirect']
    402  * 5) $_POST['redirect']
    403  * 6) $url
    404  *
    405  * @since MU
    406  * @uses wpmu_admin_redirect_add_updated_param()
    407  *
    408  * @param string $url
    409  */
     337// wpmu admin functions
     338
    410339function wpmu_admin_do_redirect( $url = '' ) {
    411340    $ref = '';
     
    436365}
    437366
    438 /**
    439  * Adds an 'updated=true' argument to a URL.
    440  *
    441  * @since MU
    442  *
    443  * @param string $url
    444  * @return string
    445  */
    446367function wpmu_admin_redirect_add_updated_param( $url = '' ) {
    447368    if ( strpos( $url, 'updated=true' ) === false ) {
     
    454375}
    455376
    456 /**
    457  * Checks an email address against a list of banned domains.
    458  *
    459  * This function checks against the Banned Email Domains list
    460  * at wp-admin/network/settings.php. The check is only run on
    461  * self-registrations; user creation at wp-admin/network/users.php
    462  * bypasses this check.
    463  *
    464  * @since MU
    465  *
    466  * @param string $user_email The email provided by the user at registration.
    467  * @return bool Returns true when the email address is banned.
    468  */
     377function is_blog_user( $blog_id = 0 ) {
     378    global $wpdb;
     379 
     380    $current_user = wp_get_current_user();
     381    if ( !$blog_id )
     382        $blog_id = $wpdb->blogid;
     383
     384    $cap_key = $wpdb->base_prefix . $blog_id . '_capabilities';
     385
     386    if ( is_array($current_user->$cap_key) && in_array(1, $current_user->$cap_key) )
     387        return true;
     388
     389    return false;
     390}
     391
    469392function is_email_address_unsafe( $user_email ) {
    470393    $banned_names = get_site_option( 'banned_email_domains' );
     
    490413}
    491414
    492 /**
    493  * Processes new user registrations.
    494  *
    495  * Checks the data provided by the user during signup. Verifies
    496  * the validity and uniqueness of user names and user email addresses,
    497  * and checks email addresses against admin-provided domain
    498  * whitelists and blacklists.
    499  *
    500  * The hook 'wpmu_validate_user_signup' provides an easy way
    501  * to modify the signup process. The value $result, which is passed
    502  * to the hook, contains both the user-provided info and the error
    503  * messages created by the function. 'wpmu_validate_user_signup' allows
    504  * you to process the data in any way you'd like, and unset the
    505  * relevant errors if necessary.
    506  *
    507  * @since MU
    508  * @uses is_email_address_unsafe()
    509  * @uses username_exists()
    510  * @uses email_exists()
    511  *
    512  * @param string $user_name The login name provided by the user.
    513  * @param string $user_email The email provided by the user.
    514  * @return array Contains username, email, and error messages.
    515  */
    516415function wpmu_validate_user_signup($user_name, $user_email) {
    517416    global $wpdb;
     
    525424
    526425    if ( $user_name != $orig_username || $user_name != $maybe[0] ) {
    527         $errors->add( 'user_name', __( 'Only lowercase letters (a-z) and numbers are allowed.' ) );
     426        $errors->add( 'user_name', __( "Only the lowercase letters a-z and numbers allowed" ) );
    528427        $user_name = $orig_username;
    529428    }
     
    606505}
    607506
    608 /**
    609  * Processes new site registrations.
    610  *
    611  * Checks the data provided by the user during blog signup. Verifies
    612  * the validity and uniqueness of blog paths and domains.
    613  *
    614  * This function prevents the current user from registering a new site
    615  * with a blogname equivalent to another user's login name. Passing the
    616  * $user parameter to the function, where $user is the other user, is
    617  * effectively an override of this limitation.
    618  *
    619  * Filter 'wpmu_validate_blog_signup' if you want to modify
    620  * the way that WordPress validates new site signups.
    621  *
    622  * @since MU
    623  * @uses domain_exists()
    624  * @uses username_exists()
    625  *
    626  * @param string $blogname The blog name provided by the user. Must be unique.
    627  * @param string $blog_title The blog title provided by the user.
    628  * @return array Contains the new site data and error messages.
    629  */
    630507function wpmu_validate_blog_signup($blogname, $blog_title, $user = '') {
    631508    global $wpdb, $domain, $base, $current_site;
     
    711588}
    712589
    713 /**
    714  * Record site signup information for future activation.
    715  *
    716  * @since MU
    717  * @uses wpmu_signup_blog_notification()
    718  *
    719  * @param string $domain The requested domain.
    720  * @param string $path The requested path.
    721  * @param string $title The requested site title.
    722  * @param string $user The user's requested login name.
    723  * @param string $user_email The user's email address.
    724  * @param array $meta By default, contains the requested privacy setting and lang_id.
    725  */
     590// Record signup information for future activation. wpmu_validate_signup() should be run
     591// on the inputs before calling wpmu_signup().
    726592function wpmu_signup_blog($domain, $path, $title, $user, $user_email, $meta = '') {
    727593    global $wpdb;
     
    747613}
    748614
    749 /**
    750  * Record user signup information for future activation.
    751  *
    752  * This function is used when user registration is open but
    753  * new site registration is not.
    754  *
    755  * @since MU
    756  * @uses wpmu_signup_user_notification()
    757  *
    758  * @param string $user The user's requested login name.
    759  * @param string $user_email The user's email address.
    760  * @param array $meta By default, this is an empty array.
    761  */
    762615function wpmu_signup_user($user, $user_email, $meta = '') {
    763616    global $wpdb;
     
    783636}
    784637
    785 /**
    786  * Notify user of signup success.
    787  *
    788  * This is the notification function used when site registration
    789  * is enabled.
    790  *
    791  * Filter 'wpmu_signup_blog_notification' to bypass this function or
    792  * replace it with your own notification behavior.
    793  *
    794  * Filter 'wpmu_signup_blog_notification_email' and
    795  * 'wpmu_signup_blog_notification_email' to change the content
    796  * and subject line of the email sent to newly registered users.
    797  *
    798  * @since MU
    799  *
    800  * @param string $domain The new blog domain.
    801  * @param string $path The new blog path.
    802  * @param string $title The site title.
    803  * @param string $user The user's login name.
    804  * @param string $user_email The user's email address.
    805  * @param array $meta By default, contains the requested privacy setting and lang_id.
    806  * @param string $key The activation key created in wpmu_signup_blog()
    807  * @return bool
    808  */
     638// Notify user of signup success.
    809639function wpmu_signup_blog_notification($domain, $path, $title, $user, $user_email, $key, $meta = '') {
    810640    global $current_site;
     
    825655    $from_name = get_site_option( 'site_name' ) == '' ? 'WordPress' : esc_html( get_site_option( 'site_name' ) );
    826656    $message_headers = "From: \"{$from_name}\" <{$admin_email}>\n" . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n";
    827     $message = sprintf(
    828         apply_filters( 'wpmu_signup_blog_notification_email',
    829             __( "To activate your blog, please click the following link:\n\n%s\n\nAfter you activate, you will receive *another email* with your login.\n\nAfter you activate, you can visit your site here:\n\n%s" ),
    830             $domain, $path, $title, $user, $user_email, $key, $meta
    831         ),
    832         $activate_url,
    833         esc_url( "http://{$domain}{$path}" ),
    834         $key
    835     );
     657    $message = sprintf( apply_filters( 'wpmu_signup_blog_notification_email', __( "To activate your blog, please click the following link:\n\n%s\n\nAfter you activate, you will receive *another email* with your login.\n\nAfter you activate, you can visit your site here:\n\n%s" ) ), $activate_url, esc_url( "http://{$domain}{$path}" ), $key );
    836658    // TODO: Don't hard code activation link.
    837     $subject = sprintf(
    838         apply_filters( 'wpmu_signup_blog_notification_subject',
    839             __( '[%1$s] Activate %2$s' ),
    840             $domain, $path, $title, $user, $user_email, $key, $meta
    841         ),
    842         $from_name,
    843         esc_url( 'http://' . $domain . $path )
    844     );
     659    $subject = sprintf( apply_filters( 'wpmu_signup_blog_notification_subject', __( '[%1$s] Activate %2$s' ) ), $from_name, esc_url( 'http://' . $domain . $path ) );
    845660    wp_mail($user_email, $subject, $message, $message_headers);
    846661    return true;
    847662}
    848663
    849 /**
    850  * Notify user of signup success.
    851  *
    852  * This is the notification function used when no new site has
    853  * been requested.
    854  *
    855  * Filter 'wpmu_signup_user_notification' to bypass this function or
    856  * replace it with your own notification behavior.
    857  *
    858  * Filter 'wpmu_signup_user_notification_email' and
    859  * 'wpmu_signup_user_notification_subject' to change the content
    860  * and subject line of the email sent to newly registered users.
    861  *
    862  * @since MU
    863  *
    864  * @param string $user The user's login name.
    865  * @param string $user_email The user's email address.
    866  * @param array $meta By default, an empty array.
    867  * @param string $key The activation key created in wpmu_signup_user()
    868  * @return bool
    869  */
    870664function wpmu_signup_user_notification($user, $user_email, $key, $meta = '') {
    871665    if ( !apply_filters('wpmu_signup_user_notification', $user, $user_email, $key, $meta) )
     
    878672    $from_name = get_site_option( 'site_name' ) == '' ? 'WordPress' : esc_html( get_site_option( 'site_name' ) );
    879673    $message_headers = "From: \"{$from_name}\" <{$admin_email}>\n" . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n";
    880     $message = sprintf(
    881         apply_filters( 'wpmu_signup_user_notification_email',
    882             __( "To activate your user, please click the following link:\n\n%s\n\nAfter you activate, you will receive *another email* with your login.\n\n" ),
    883             $user, $user_email, $key, $meta
    884         ),
    885         site_url( "wp-activate.php?key=$key" ),
    886         $key
    887     );
     674    $message = sprintf( apply_filters( 'wpmu_signup_user_notification_email', __( "To activate your user, please click the following link:\n\n%s\n\nAfter you activate, you will receive *another email* with your login.\n\n" ) ), site_url( "wp-activate.php?key=$key" ), $key );
    888675    // TODO: Don't hard code activation link.
    889     $subject = sprintf(
    890         apply_filters( 'wpmu_signup_user_notification_subject',
    891             __( '[%1$s] Activate %2$s' ),
    892             $user, $user_email, $key, $meta
    893         ),
    894         $from_name,
    895         $user
    896     );
     676    $subject = sprintf( __( apply_filters( 'wpmu_signup_user_notification_subject', '[%1$s] Activate %2$s' ) ), $from_name, $user);
    897677    wp_mail($user_email, $subject, $message, $message_headers);
    898678    return true;
    899679}
    900680
    901 /**
    902  * Activate a signup.
    903  *
    904  * Hook to 'wpmu_activate_user' or 'wpmu_activate_blog' for events
    905  * that should happen only when users or sites are self-created (since
    906  * those actions are not called when users and sites are created
    907  * by a Super Admin).
    908  *
    909  * @since MU
    910  * @uses wp_generate_password()
    911  * @uses wpmu_welcome_user_notification()
    912  * @uses add_user_to_blog()
    913  * @uses add_new_user_to_blog()
    914  * @uses wpmu_create_user()
    915  * @uses wpmu_create_blog()
    916  * @uses wpmu_welcome_notification()
    917  *
    918  * @param string $key The activation key provided to the user.
    919  * @return array An array containing information about the activated user and/or blog
    920  */
    921681function wpmu_activate_signup($key) {
    922682    global $wpdb, $current_site;
     
    924684    $signup = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->signups WHERE activation_key = %s", $key) );
    925685
    926     if ( empty( $signup ) )
    927         return new WP_Error( 'invalid_key', __( 'Invalid activation key.' ) );
    928 
    929     if ( $signup->active ) {
    930         if ( empty( $signup->domain ) )
    931             return new WP_Error( 'already_active', __( 'The user is already active.' ), $signup );
    932         else
    933             return new WP_Error( 'already_active', __( 'The site is already active.' ), $signup );
    934     }
     686    if ( empty($signup) )
     687        return new WP_Error('invalid_key', __('Invalid activation key.'));
     688
     689    if ( $signup->active )
     690        return new WP_Error('already_active', __('The site is already active.'), $signup);
    935691
    936692    $meta = unserialize($signup->meta);
    937693    $user_login = $wpdb->escape($signup->user_login);
    938694    $user_email = $wpdb->escape($signup->user_email);
    939     $password = wp_generate_password( 12, false );
     695    $password = wp_generate_password();
    940696
    941697    $user_id = username_exists($user_login);
     
    958714
    959715        wpmu_welcome_user_notification($user_id, $password, $meta);
     716        $user_site = get_site_option( 'dashboard_blog', $current_site->blog_id );
     717
     718        if ( $user_site == false )
     719            add_user_to_blog( '1', $user_id, get_site_option( 'default_user_role', 'subscriber' ) );
     720        else
     721            add_user_to_blog( $user_site, $user_id, get_site_option( 'default_user_role', 'subscriber' ) );
    960722
    961723        add_new_user_to_blog( $user_id, $user_email, $meta );
     
    984746}
    985747
    986 /**
    987  * Create a user.
    988  *
    989  * This function runs when a user self-registers as well as when
    990  * a Super Admin creates a new user. Hook to 'wpmu_new_user' for events
    991  * that should affect all new users, but only on Multisite (otherwise
    992  * use 'user_register').
    993  *
    994  * @since MU
    995  * @uses wp_create_user()
    996  *
    997  * @param string $user_name The new user's login name.
    998  * @param string $password The new user's password.
    999  * @param string $email The new user's email address.
    1000  * @return mixed Returns false on failure, or int $user_id on success
    1001  */
    1002748function wpmu_create_user( $user_name, $password, $email) {
    1003749    $user_name = preg_replace( '/\s+/', '', sanitize_user( $user_name, true ) );
     
    1016762}
    1017763
    1018 /**
    1019  * Create a site.
    1020  *
    1021  * This function runs when a user self-registers a new site as well
    1022  * as when a Super Admin creates a new site. Hook to 'wpmu_new_blog'
    1023  * for events that should affect all new sites.
    1024  *
    1025  * On subdirectory installs, $domain is the same as the main site's
    1026  * domain, and the path is the subdirectory name (eg 'example.com'
    1027  * and '/blog1/'). On subdomain installs, $domain is the new subdomain +
    1028  * root domain (eg 'blog1.example.com'), and $path is '/'.
    1029  *
    1030  * @since MU
    1031  * @uses domain_exists()
    1032  * @uses insert_blog()
    1033  * @uses wp_install_defaults()
    1034  * @uses add_user_to_blog()
    1035  *
    1036  * @param string $domain The new site's domain.
    1037  * @param string $path The new site's path.
    1038  * @param string $title The new site's title.
    1039  * @param int $user_id The user ID of the new site's admin.
    1040  * @param array $meta Optional. Used to set initial site options.
    1041  * @param int $site_id Optional. Only relevant on multi-network installs.
    1042  * @return mixed Returns WP_Error object on failure, int $blog_id on success
    1043  */
    1044764function wpmu_create_blog($domain, $path, $title, $user_id, $meta = '', $site_id = 1) {
    1045765    $domain = preg_replace( '/\s+/', '', sanitize_user( $domain, true ) );
     
    1080800    update_option( 'blog_public', (int)$meta['public'] );
    1081801
    1082     if ( !is_super_admin() && ! get_user_meta( $user_id, 'primary_blog', true ) )
     802    if ( !is_super_admin() && get_user_meta( $user_id, 'primary_blog', true ) == get_site_option( 'dashboard_blog', 1 ) )
    1083803        update_user_meta( $user_id, 'primary_blog', $blog_id );
    1084804
     
    1089809}
    1090810
    1091 /**
    1092  * Notifies the network admin that a new site has been activated.
    1093  *
    1094  * Filter 'newblog_notify_siteadmin' to change the content of
    1095  * the notification email.
    1096  *
    1097  * @since MU
    1098  *
    1099  * @param int $blog_id The new site's ID.
    1100  * @return bool
    1101  */
    1102811function newblog_notify_siteadmin( $blog_id, $deprecated = '' ) {
    1103812    if ( get_site_option( 'registrationnotification' ) != 'yes' )
     
    1108817        return false;
    1109818
    1110     $options_site_url = esc_url(network_admin_url('settings.php'));
     819    $options_site_url = esc_url(network_admin_url('ms-options.php'));
    1111820
    1112821    switch_to_blog( $blog_id );
     
    1126835}
    1127836
    1128 /**
    1129  * Notifies the network admin that a new user has been activated.
    1130  *
    1131  * Filter 'newuser_notify_siteadmin' to change the content of
    1132  * the notification email.
    1133  *
    1134  * @since MU
    1135  *
    1136  * @param int $user_id The new user's ID.
    1137  * @return bool
    1138  */
    1139837function newuser_notify_siteadmin( $user_id ) {
    1140838    if ( get_site_option( 'registrationnotification' ) != 'yes' )
     
    1148846    $user = new WP_User($user_id);
    1149847
    1150     $options_site_url = esc_url(network_admin_url('settings.php'));
     848    $options_site_url = esc_url(network_admin_url('ms-options.php'));
    1151849    $msg = sprintf(__('New User: %1s
    1152850Remote IP: %2s
     
    1159857}
    1160858
    1161 /**
    1162  * Check whether a blogname is already taken.
    1163  *
    1164  * Used during the new site registration process to ensure
    1165  * that each blogname is unique.
    1166  *
    1167  * @since MU
    1168  *
    1169  * @param string $domain The domain to be checked.
    1170  * @param string $path The path to be checked.
    1171  * @param int $site_id Optional. Relevant only on multi-network installs.
    1172  * @return int
    1173  */
    1174859function domain_exists($domain, $path, $site_id = 1) {
    1175860    global $wpdb;
     
    1177862}
    1178863
    1179 /**
    1180  * Store basic site info in the blogs table.
    1181  *
    1182  * This function creates a row in the wp_blogs table and returns
    1183  * the new blog's ID. It is the first step in creating a new blog.
    1184  *
    1185  * @since MU
    1186  *
    1187  * @param string $domain The domain of the new site.
    1188  * @param string $path The path of the new site.
    1189  * @param int $site_id Unless you're running a multi-network install, be sure to set this value to 1.
    1190  * @return int The ID of the new row
    1191  */
    1192864function insert_blog($domain, $path, $site_id) {
    1193865    global $wpdb;
     
    1204876}
    1205877
    1206 /**
    1207  * Install an empty blog.
    1208  *
    1209  * Creates the new blog tables and options. If calling this function
    1210  * directly, be sure to use switch_to_blog() first, so that $wpdb
    1211  * points to the new blog.
    1212  *
    1213  * @since MU
    1214  * @uses make_db_current_silent()
    1215  * @uses populate_roles()
    1216  *
    1217  * @param int $blog_id The value returned by insert_blog().
    1218  * @param string $blog_title The title of the new site.
    1219  */
     878// Install an empty blog.  wpdb should already be switched.
    1220879function install_blog($blog_id, $blog_title = '') {
    1221880    global $wpdb, $table_prefix, $wp_roles;
     
    1244903    update_option('home', $url);
    1245904    update_option('fileupload_url', $url . "files" );
    1246     update_option('upload_path', UPLOADBLOGSDIR . "/$blog_id/files");
     905    update_option('upload_path', "wp-content/blogs.dir/" . $blog_id . "/files");
    1247906    update_option('blogname', stripslashes( $blog_title ) );
    1248907    update_option('admin_email', '');
     
    1256915}
    1257916
    1258 /**
    1259  * Set blog defaults.
    1260  *
    1261  * This function creates a row in the wp_blogs table.
    1262  *
    1263  * @since MU
    1264  * @deprecated MU
    1265  * @deprecated Use wp_install_defaults()
    1266  * @uses wp_install_defaults()
    1267  *
    1268  * @param int $blog_id Ignored in this function.
    1269  * @param int $user_id
    1270  */
     917// Deprecated, use wp_install_defaults()
     918// should be switched already as $blog_id is ignored.
    1271919function install_blog_defaults($blog_id, $user_id) {
    1272920    global $wpdb;
     
    1281929}
    1282930
    1283 /**
    1284  * Notify a user that her blog activation has been successful.
    1285  *
    1286  * Filter 'wpmu_welcome_notification' to disable or bypass.
    1287  *
    1288  * Filter 'update_welcome_email' and 'update_welcome_subject' to
    1289  * modify the content and subject line of the notification email.
    1290  *
    1291  * @since MU
    1292  *
    1293  * @param int $blog_id
    1294  * @param int $user_id
    1295  * @param string $password
    1296  * @param string $title The new blog's title
    1297  * @param array $meta Optional. Not used in the default function, but is passed along to hooks for customization.
    1298  * @return bool
    1299  */
    1300931function wpmu_welcome_notification($blog_id, $user_id, $password, $title, $meta = '') {
    1301932    global $current_site;
     
    1348979}
    1349980
    1350 /**
    1351  * Notify a user that her account activation has been successful.
    1352  *
    1353  * Filter 'wpmu_welcome_user_notification' to disable or bypass.
    1354  *
    1355  * Filter 'update_welcome_user_email' and 'update_welcome_user_subject' to
    1356  * modify the content and subject line of the notification email.
    1357  *
    1358  * @since MU
    1359  *
    1360  * @param int $user_id
    1361  * @param string $password
    1362  * @param array $meta Optional. Not used in the default function, but is passed along to hooks for customization.
    1363  * @return bool
    1364  */
    1365981function wpmu_welcome_user_notification($user_id, $password, $meta = '') {
    1366982    global $current_site;
     
    13961012}
    13971013
    1398 /**
    1399  * Get the current site info.
    1400  *
    1401  * Returns an object containing the ID, domain, path, and site_name
    1402  * of the site being viewed.
    1403  *
    1404  * @since MU
    1405  *
    1406  * @return object
    1407  */
    14081014function get_current_site() {
    14091015    global $current_site;
     
    14111017}
    14121018
    1413 /**
    1414  * Get a numeric user ID from either an email address or a login.
    1415  *
    1416  * @since MU
    1417  * @uses is_email()
    1418  *
    1419  * @param string $string
    1420  * @return int
    1421  */
    14221019function get_user_id_from_string( $string ) {
    14231020    $user_id = 0;
     
    14371034}
    14381035
    1439 /**
    1440  * Get a user's most recent post.
    1441  *
    1442  * Walks through each of a user's blogs to find the post with
    1443  * the most recent post_date_gmt.
    1444  *
    1445  * @since MU
    1446  * @uses get_blogs_of_user()
    1447  *
    1448  * @param int $user_id
    1449  * @return array Contains the blog_id, post_id, post_date_gmt, and post_gmt_ts
    1450  */
    14511036function get_most_recent_post_of_user( $user_id ) {
    14521037    global $wpdb;
     
    14811066}
    14821067
    1483 // Misc functions
    1484 
    1485 /**
    1486  * Get the size of a directory.
    1487  *
    1488  * A helper function that is used primarily to check whether
    1489  * a blog has exceeded its allowed upload space.
    1490  *
    1491  * @since MU
    1492  * @uses recurse_dirsize()
    1493  *
    1494  * @param string $directory
    1495  * @return int
    1496  */
     1068/* Misc functions */
    14971069function get_dirsize( $directory ) {
    14981070    $dirsize = get_transient( 'dirsize_cache' );
     
    15091081}
    15101082
    1511 /**
    1512  * Get the size of a directory recursively.
    1513  *
    1514  * Used by get_dirsize() to get a directory's size when it contains
    1515  * other directories.
    1516  *
    1517  * @since MU
    1518  *
    1519  * @param string $directory
    1520  * @return int
    1521  */
    15221083function recurse_dirsize( $directory ) {
    15231084    $size = 0;
     
    15471108}
    15481109
    1549 /**
    1550  * Check whether a blog has used its allotted upload space.
    1551  *
    1552  * Used by get_dirsize() to get a directory's size when it contains
    1553  * other directories.
    1554  *
    1555  * @since MU
    1556  * @uses get_dirsize()
    1557  *
    1558  * @param bool $echo Optional. If $echo is set and the quota is exceeded, a warning message is echoed. Default is true.
    1559  * @return int
    1560  */
    15611110function upload_is_user_over_quota( $echo = true ) {
    15621111    if ( get_site_option( 'upload_space_check_disabled' ) )
    1563         return false;
     1112        return true;
    15641113
    15651114    $spaceAllowed = get_space_allowed();
     
    15791128}
    15801129
    1581 /**
    1582  * Check an array of MIME types against a whitelist.
    1583  *
    1584  * WordPress ships with a set of allowed upload filetypes,
    1585  * which is defined in wp-includes/functions.php in
    1586  * get_allowed_mime_types(). This function is used to filter
    1587  * that list against the filetype whitelist provided by Multisite
    1588  * Super Admins at wp-admin/network/settings.php.
    1589  *
    1590  * @since MU
    1591  *
    1592  * @param array $mimes
    1593  * @return array
    1594  */
    15951130function check_upload_mimes( $mimes ) {
    15961131    $site_exts = explode( ' ', get_site_option( 'upload_filetypes' ) );
     
    16041139}
    16051140
    1606 /**
    1607  * Update a blog's post count.
    1608  *
    1609  * WordPress MS stores a blog's post count as an option so as
    1610  * to avoid extraneous COUNTs when a blog's details are fetched
    1611  * with get_blog_details(). This function is called when posts
    1612  * are published to make sure the count stays current.
    1613  *
    1614  * @since MU
    1615  */
    16161141function update_posts_count( $deprecated = '' ) {
    16171142    global $wpdb;
     
    16191144}
    16201145
    1621 /**
    1622  * Logs user registrations.
    1623  *
    1624  * @since MU
    1625  *
    1626  * @param int $blog_id
    1627  * @param int $user_id
    1628  */
    16291146function wpmu_log_new_registrations( $blog_id, $user_id ) {
    16301147    global $wpdb;
     
    16331150}
    16341151
    1635 /**
    1636  * Get the remaining upload space for this blog.
    1637  *
    1638  * @since MU
    1639  * @uses upload_is_user_over_quota()
    1640  * @uses get_space_allowed()
    1641  * @uses get_dirsize()
    1642  *
    1643  * @param int $size
    1644  * @return int
    1645  */
    16461152function fix_import_form_size( $size ) {
    16471153    if ( upload_is_user_over_quota( false ) == true )
     
    17251231}
    17261232
    1727 /**
    1728  * Ensure that the current site's domain is listed in the allowed redirect host list.
    1729  *
    1730  * @see wp_validate_redirect()
    1731  * @since MU
    1732  *
    1733  * @return array The current site's domain
    1734  */
    17351233function redirect_this_site( $deprecated = '' ) {
    17361234    global $current_site;
     
    17381236}
    17391237
    1740 /**
    1741  * Check whether an upload is too big.
    1742  *
    1743  * @since MU
    1744  *
    1745  * @param array $upload
    1746  * @return mixed If the upload is under the size limit, $upload is returned. Otherwise returns an error message.
    1747  */
    17481238function upload_is_file_too_big( $upload ) {
    17491239    if ( is_array( $upload ) == false || defined( 'WP_IMPORTING' ) )
     
    17561246}
    17571247
    1758 /**
    1759  * Add a nonce field to the signup page.
    1760  *
    1761  * @since MU
    1762  * @uses wp_nonce_field()
    1763  */
     1248function wordpressmu_wp_mail_from( $email ) {
     1249    if ( strpos( $email, 'wordpress@' ) !== false )
     1250        $email = get_option( 'admin_email' );
     1251    return $email;
     1252}
     1253
    17641254function signup_nonce_fields() {
    17651255    $id = mt_rand();
     
    17681258}
    17691259
    1770 /**
    1771  * Process the signup nonce created in signup_nonce_fields().
    1772  *
    1773  * @since MU
    1774  * @uses wp_create_nonce()
    1775  *
    1776  * @param array $result
    1777  * @return array
    1778  */
    17791260function signup_nonce_check( $result ) {
    17801261    if ( !strpos( $_SERVER[ 'PHP_SELF' ], 'wp-signup.php' ) )
     
    17871268}
    17881269
    1789 /**
    1790  * Correct 404 redirects when NOBLOGREDIRECT is defined.
    1791  *
    1792  * @since MU
    1793  */
    17941270function maybe_redirect_404() {
    17951271    global $current_site;
     
    18021278}
    18031279
    1804 /**
    1805  * Add a new user to a blog by visiting /newbloguser/username/.
    1806  *
    1807  * This will only work when the user's details are saved as an option
    1808  * keyed as 'new_user_x', where 'x' is the username of the user to be
    1809  * added, as when a user is invited through the regular WP Add User interface.
    1810  *
    1811  * @since MU
    1812  * @uses add_existing_user_to_blog()
    1813  */
    18141280function maybe_add_existing_user_to_blog() {
    18151281    if ( false === strpos( $_SERVER[ 'REQUEST_URI' ], '/newbloguser/' ) )
     
    18321298}
    18331299
    1834 /**
    1835  * Add a user to a blog based on details from maybe_add_existing_user_to_blog().
    1836  *
    1837  * @since MU
    1838  * @uses add_user_to_blog()
    1839  *
    1840  * @param array $details
    1841  */
    18421300function add_existing_user_to_blog( $details = false ) {
    1843     global $blog_id;
    1844 
    18451301    if ( is_array( $details ) ) {
    1846         $result = add_user_to_blog( $blog_id, $details[ 'user_id' ], $details[ 'role' ] );
     1302        $result = add_user_to_blog( '', $details[ 'user_id' ], $details[ 'role' ] );
    18471303        do_action( 'added_existing_user', $details[ 'user_id' ], $result );
    18481304    }
     
    18501306}
    18511307
    1852 /**
    1853  * Add a newly created user to the appropriate blog
    1854  *
    1855  * @since MU
    1856  *
    1857  * @param int $user_id
    1858  * @param string $email
    1859  * @param array $meta
    1860  */
    18611308function add_new_user_to_blog( $user_id, $email, $meta ) {
    18621309    global $current_site;
     
    18641311        $blog_id = $meta[ 'add_to_blog' ];
    18651312        $role = $meta[ 'new_role' ];
    1866         remove_user_from_blog($user_id, $current_site->blog_id); // remove user from main blog.
     1313        remove_user_from_blog($user_id, $current_site->blogid); // remove user from main blog.
    18671314        add_user_to_blog( $blog_id, $user_id, $role );
    18681315        update_user_meta( $user_id, 'primary_blog', $blog_id );
     
    18701317}
    18711318
    1872 /**
    1873  * Correct From host on outgoing mail to match the site domain
    1874  *
    1875  * @since MU
    1876  */
    18771319function fix_phpmailer_messageid( $phpmailer ) {
    18781320    global $current_site;
     
    18801322}
    18811323
    1882 /**
    1883  * Check to see whether a user is marked as a spammer, based on username
    1884  *
    1885  * @since MU
    1886  * @uses get_current_user_id()
    1887  * @uses get_user_id_from_string()
    1888  *
    1889  * @param string $username
    1890  * @return bool
    1891  */
    18921324function is_user_spammy( $username = 0 ) {
    18931325    if ( $username == 0 ) {
     
    19011333}
    19021334
    1903 /**
    1904  * Update this blog's 'public' setting in the global blogs table.
    1905  *
    1906  * Public blogs have a setting of 1, private blogs are 0.
    1907  *
    1908  * @since MU
    1909  * @uses update_blog_status()
    1910  *
    1911  * @param int $old_value
    1912  * @param int $value The new public value
    1913  * @return bool
    1914  */
    19151335function update_blog_public( $old_value, $value ) {
    19161336    global $wpdb;
     
    19201340add_action('update_option_blog_public', 'update_blog_public', 10, 2);
    19211341
    1922 /**
    1923  * Get the "dashboard blog", the blog where users without a blog edit their profile data.
    1924  *
    1925  * @since MU
    1926  * @uses get_blog_details()
    1927  *
    1928  * @return int
    1929  */
     1342/* Redirect all hits to "dashboard" blog to wp-admin/ Dashboard. */
     1343function redirect_mu_dashboard() {
     1344    global $current_site, $current_blog;
     1345
     1346    $dashboard_blog = get_dashboard_blog();
     1347    if ( $current_blog->blog_id == $dashboard_blog->blog_id && $dashboard_blog->blog_id != $current_site->blog_id ) {
     1348        $protocol = ( is_ssl() ? 'https://' : 'http://' );
     1349        wp_redirect( $protocol . $dashboard_blog->domain . trailingslashit( $dashboard_blog->path ) . 'wp-admin/' );
     1350        die();
     1351    }
     1352}
     1353add_action( 'template_redirect', 'redirect_mu_dashboard' );
     1354
    19301355function get_dashboard_blog() {
    19311356    if ( $blog = get_site_option( 'dashboard_blog' ) )
     
    19351360}
    19361361
    1937 /**
    1938  * Check whether a usermeta key has to do with the current blog.
    1939  *
    1940  * @since MU
    1941  * @uses wp_get_current_user()
    1942  *
    1943  * @param string $key
    1944  * @param int $user_id Optional. Defaults to current user.
    1945  * @param int $blog_id Optional. Defaults to current blog.
    1946  * @return bool
    1947  */
    19481362function is_user_option_local( $key, $user_id = 0, $blog_id = 0 ) {
    19491363    global $wpdb;
     
    19631377}
    19641378
    1965 /**
    1966  * Check whether users can self-register, based on Network settings.
    1967  *
    1968  * @since MU
    1969  *
    1970  * @return bool
    1971  */
    19721379function users_can_register_signup_filter() {
    19731380    $registration = get_site_option('registration');
     
    19791386add_filter('option_users_can_register', 'users_can_register_signup_filter');
    19801387
    1981 /**
    1982  * Ensure that the welcome message is not empty. Currently unused.
    1983  *
    1984  * @since MU
    1985  *
    1986  * @param string $text
    1987  * @return string
    1988  */
    19891388function welcome_user_msg_filter( $text ) {
    19901389    if ( !$text ) {
     
    20461445}
    20471446
    2048 /**
    2049  * Schedule update of the network-wide counts for the current network.
    2050  *
    2051  * @since 3.1.0
    2052  */
    2053 function wp_schedule_update_network_counts() {
    2054     if ( !is_main_site() )
    2055         return;
    2056 
    2057     if ( !wp_next_scheduled('update_network_counts') && !defined('WP_INSTALLING') )
    2058         wp_schedule_event(time(), 'twicedaily', 'update_network_counts');
    2059 }
    2060 
    2061 /**
    2062  *  Update the network-wide counts for the current network.
    2063  *
    2064  *  @since 3.1.0
    2065  */
    2066 function wp_update_network_counts() {
    2067     global $wpdb;
    2068 
    2069     $count = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(blog_id) as c FROM $wpdb->blogs WHERE site_id = %d AND spam = '0' AND deleted = '0' and archived = '0'", $wpdb->siteid) );
    2070     update_site_option( 'blog_count', $count );
    2071 
    2072     $count = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(ID) as c FROM $wpdb->users WHERE spam = '0' AND deleted = '0'") );
    2073     update_site_option( 'user_count', $count );
    2074 }
    2075 
    20761447?>
Note: See TracChangeset for help on using the changeset viewer.