WordPress.org

Make WordPress Core

Ticket #12531: 12531.5.patch

File 12531.5.patch, 7.9 KB (added by ocean90, 5 years ago)
  • wp-admin/admin.php

     
    3737                 * 
    3838                 * @since 2.8.4b 
    3939                 */ 
    40                 $c = get_blog_count(); 
     40                $c = ms_count_blogs(); 
     41                $c = $c->active; 
    4142                if ( $c <= 50 || ( $c > 50 && mt_rand( 0, (int)( $c / 50 ) ) == 1 ) ) { 
    4243                        require_once( ABSPATH . WPINC . '/http.php' ); 
    4344                        $response = wp_remote_get( admin_url( 'upgrade.php?step=1' ), array( 'timeout' => 120, 'httpversion' => '1.1' ) ); 
  • wp-admin/includes/ms.php

     
    161161        // allow for commit transaction 
    162162        do_action('deleted_user', $id); 
    163163 
     164        delete_site_transient( 'user_count' ); 
     165 
    164166        return true; 
    165167} 
    166168 
     
    498500                        do_action( "make_ham_user", $id ); 
    499501        } 
    500502 
     503        delete_site_transient( 'user_count' ); 
     504 
    501505        return $value; 
    502506} 
    503507 
  • wp-admin/ms-admin.php

     
    1818        wp_die( __('You do not have permission to access this page.') ); 
    1919 
    2020global $wpdb; 
    21 $c_users = get_user_count(); 
    22 $c_blogs = get_blog_count(); 
     21$c_users = ms_count_users(); 
     22$c_blogs = ms_count_blogs(); 
    2323 
    24 $user_text = sprintf( _n( '%s user', '%s users', $c_users ), number_format_i18n( $c_users ) ); 
    25 $blog_text = sprintf( _n( '%s site', '%s sites', $c_blogs ), number_format_i18n( $c_blogs ) ); 
     24$user_text = sprintf( _n( '%s user', '%s users', $c_users->active ), number_format_i18n( $c_users->active ) ); 
     25$blog_text = sprintf( _n( '%s site', '%s sites', $c_blogs->active ), number_format_i18n( $c_blogs->active ) ); 
    2626 
    2727$sentence = sprintf( __( 'You have %1$s and %2$s.' ), $blog_text, $user_text ); 
    2828?> 
  • wp-includes/ms-blogs.php

     
    502502                        do_action( "make_ham_blog", $blog_id ); 
    503503        } 
    504504 
     505        delete_site_transient( 'blog_count' ); 
     506 
    505507        return $value; 
    506508} 
    507509 
  • wp-includes/ms-deprecated.php

     
    2424} 
    2525 
    2626/** 
     27 * @since unknown 
     28 * @deprecated 3.0.0 
     29 * @deprecated Use ms_count_blogs() 
     30 * @see ms_count_blogs() 
     31 */ 
     32function get_blog_count( $id = '' ) { 
     33        _deprecated_function( __FUNCTION__, '3.0', 'ms_count_blogs()' ); 
     34 
     35        $count = ms_count_blogs( $id ); 
     36 
     37        return $count->active; 
     38} 
     39 
     40/** 
     41 * @since unknown 
     42 * @deprecated 3.0.0 
     43 * @deprecated Use ms_count_users() 
     44 * @see ms_count_users() 
     45 */ 
     46function get_user_count() { 
     47        _deprecated_function( __FUNCTION__, '3.0', 'ms_count_users()' ); 
     48 
     49        $count = ms_count_users(); 
     50 
     51        return $count->active; 
     52} 
     53 
     54/** 
    2755 * Determine if user is a site admin. 
    2856 * 
    2957 * Plugins should use is_multisite() instead of checking if this function exists 
  • wp-includes/ms-functions.php

     
    66 */ 
    77 
    88function get_sitestats() { 
    9         global $wpdb; 
     9        $count_blog =  ms_count_blogs(); 
     10        $count_users = ms_count_users(); 
     11        $stats['blogs'] = $count_blog->active; 
     12        $stats['users'] = $count_users->active; 
    1013 
    11         $stats['blogs'] = get_blog_count(); 
    12  
    13         $count_ts = get_site_option( 'user_count_ts' ); 
    14         if ( time() - $count_ts > 3600 ) { 
    15                 $count = $wpdb->get_var( "SELECT COUNT(ID) FROM $wpdb->users" ); 
    16                 update_site_option( 'user_count', $count ); 
    17                 update_site_option( 'user_count_ts', time() ); 
    18         } else { 
    19                 $count = get_site_option( 'user_count' ); 
    20         } 
    21         $stats['users'] = $count; 
    2214        return $stats; 
    2315} 
    2416 
     
    199191        return array_slice( $most_active, 0, $num ); 
    200192} 
    201193 
    202 function get_user_count() { 
     194/** 
     195 * Retrieve total users  
     196 * 
     197 * The properties of the returned object contain the 'spam' and 'deleted' 
     198 * users. Those properties contain the amount of users that match 
     199 * the status. The 'active' property contains the integer of users, which are not 
     200 * 'spam' and 'deleted'. The 'total' property contains the integer of total users. 
     201 * 
     202 * The user stats are cached and then retrieved, if they already exist in the 
     203 * cache. 
     204 * 
     205 * @since 3.0.0 
     206 * 
     207 * @return object User stats. 
     208 */ 
     209function ms_count_users() { 
    203210        global $wpdb; 
    204211 
    205         $count_ts = get_site_option( "user_count_ts" ); 
    206         if ( time() - $count_ts > 3600 ) { 
    207                 $count = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(ID) as c FROM $wpdb->users WHERE spam = '0' AND deleted = '0'") ); 
    208                 update_site_option( "user_count", $count ); 
    209                 update_site_option( "user_count_ts", time() ); 
     212        $count = get_site_transient( 'user_count' ); 
     213 
     214        if ( false !== $count ) 
     215                return $count; 
     216 
     217        $count_users = $wpdb->get_results( "SELECT spam, deleted, COUNT(ID) as num_users FROM $wpdb->users GROUP BY spam, deleted", ARRAY_A ); 
     218        $count['spam'] = $count['deleted'] = $count['total'] = $count['active'] = 0; 
     219 
     220        foreach ( (array) $count_users as $row ) { 
     221                $count['total'] += $row['num_users']; 
     222 
     223                if ( $row['spam'] == 1 ) 
     224                        $count['spam'] += $row['num_users']; 
     225                if ( $row['deleted'] == 1 ) 
     226                        $count['deleted'] += $row['num_users']; 
     227                if ( $row['spam'] != 1 && $row['deleted'] != 1 ) 
     228                        $count['active'] = $row['num_users']; 
    210229        } 
    211230 
    212         $count = get_site_option( "user_count" ); 
     231        $count = (object) $count; 
     232        set_site_transient( 'user_count', $count ); 
    213233 
    214234        return $count; 
    215235} 
    216236 
    217 function get_blog_count( $id = 0 ) { 
     237/** 
     238 * Retrieve total blogs  
     239 * 
     240 * The properties of the returned object contain the 'spam', 'deleted' 
     241 * and 'archived' blogs. Those properties contain the amount of blogs that match 
     242 * the status. The 'active' property contains the integer of blogs, which are not 
     243 * 'spam', 'deleted' and 'archived'. The 'total' property contains the integer of 
     244 * total blogs. 
     245 * 
     246 * The blog stats are cached and then retrieved, if they already exist in the 
     247 * cache. 
     248 * 
     249 * @since 3.0.0 
     250 * 
     251 * @param int $id Optional. Site ID. 
     252 * @return object Blog stats. 
     253 */ 
     254function ms_count_blogs( $id = 0 ) { 
    218255        global $wpdb; 
    219256 
    220257        if ( $id == 0 ) 
    221258                $id = $wpdb->siteid; 
    222259 
    223         $count_ts = get_site_option( "blog_count_ts" ); 
    224         if ( time() - $count_ts > 3600 ) { 
    225                 $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) ); 
    226                 update_site_option( "blog_count", $count ); 
    227                 update_site_option( "blog_count_ts", time() ); 
     260        $count = get_site_transient( 'blog_count' ); 
     261 
     262        if ( false !== $count ) 
     263                return $count; 
     264 
     265        $count_blogs = $wpdb->get_results( $wpdb->prepare( "SELECT spam, deleted, archived, mature, COUNT(blog_id) as num_blogs FROM $wpdb->blogs WHERE site_id = %d GROUP BY spam, deleted, archived, mature", $id ), ARRAY_A ); 
     266        $count['spam'] = $count['archived'] = $count['deleted'] = $count['mature'] = $count['total'] = $count['active'] = 0; 
     267 
     268        foreach ( (array) $count_blogs as $row ) { 
     269                $count['total'] += $row['num_blogs']; 
     270 
     271                if ( $row['spam'] == 1 ) 
     272                        $count['spam'] += $row['num_blogs']; 
     273                if ( $row['archived'] == 1 ) 
     274                        $count['archived'] += $row['num_blogs']; 
     275                if ( $row['deleted'] == 1 ) 
     276                        $count['deleted'] += $row['num_blogs']; 
     277                if ( $row['mature'] == 1 ) 
     278                        $count['mature'] += $row['num_blogs']; 
     279                if ( $row['spam'] != 1 && $row['archived'] != 1 && $row['deleted'] != 1 && $row['mature'] != 1 ) 
     280                        $count['active'] = $row['num_blogs']; 
    228281        } 
    229282 
    230         $count = get_site_option( "blog_count" ); 
     283        $count = (object) $count; 
     284        set_site_transient( 'blog_count', $count ); 
    231285 
    232286        return $count; 
    233287} 
     
    790844 
    791845        do_action( 'wpmu_new_user', $user_id ); 
    792846 
     847        delete_site_transient( 'user_count' ); 
     848 
    793849        return $user_id; 
    794850} 
    795851