WordPress.org

Make WordPress Core

Ticket #12531: 12531.2.patch

File 12531.2.patch, 6.1 KB (added by ocean90, 8 years ago)

add get_sitestats() to ms-deprecated.php

  • wp-admin/admin.php

     
    3838                 * @since 2.8.4b
    3939                 */
    4040                $c = get_blog_count();
     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

     
    160160
    161161        // allow for commit transaction
    162162        do_action('deleted_user', $id);
     163       
     164        delete_site_transient( "user_count" );
    163165
    164166        return true;
    165167}
     
    497499                else
    498500                        do_action( "make_ham_user", $id );
    499501        }
    500 
     502       
     503        delete_site_transient( "user_count" );
     504       
    501505        return $value;
    502506}
    503507
  • wp-admin/ms-admin.php

     
    2121$c_users = get_user_count();
    2222$c_blogs = get_blog_count();
    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

     
    501501                else
    502502                        do_action( "make_ham_blog", $blog_id );
    503503        }
     504       
     505        delete_site_transient( "blog_count" );
    504506
    505507        return $value;
    506508}
  • wp-includes/ms-deprecated.php

     
    2424}
    2525
    2626/**
     27 * @since unknown
     28 * @deprecated 3.0.0
     29 * @deprecated Use get_user_count() and/or get_blog_count()
     30 * @see get_user_count()/get_blog_count()
     31 */
     32function get_sitestats() {
     33        _deprecated_function( __FUNCTION__, '3.0', 'get_user_count() / get_blog_count()' );
     34}
     35
     36/**
    2737 * Determine if user is a site admin.
    2838 *
    2939 * Plugins should use is_multisite() instead of checking if this function exists
  • wp-includes/ms-functions.php

     
    55 * @package WordPress
    66 */
    77
    8 function get_sitestats() {
    9         global $wpdb;
    10 
    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;
    22         return $stats;
    23 }
    24 
    258function get_admin_users_for_domain( $sitedomain = '', $path = '' ) {
    269        global $wpdb;
    2710
     
    201184
    202185function get_user_count() {
    203186        global $wpdb;
     187       
     188        $count = get_site_transient( "user_count" );
     189       
     190        if ( false !== $count )
     191                return $count;
     192               
     193        $count['active'] = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(ID) as c FROM $wpdb->users WHERE spam = '0' AND deleted = '0'") );
     194        $count['all'] = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(ID) as c FROM $wpdb->users") );
     195        $count['spam'] = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(ID) as c FROM $wpdb->users WHERE spam = '1'") );
     196        $count['deleted'] = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(ID) as c FROM $wpdb->users WHERE deleted = '1'") );
    204197
    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() );
    210         }
    211 
    212         $count = get_site_option( "user_count" );
    213 
     198        $count = (object) $count;
     199        set_site_transient( "user_count", $count );
     200       
    214201        return $count;
    215202}
    216203
     
    220207        if ( $id == 0 )
    221208                $id = $wpdb->siteid;
    222209
    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() );
    228         }
     210        $count = get_site_transient( "blog_count" );
     211       
     212        if ( false !== $count )
     213                return $count;
     214               
     215        $count['active'] = $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) );
     216        $count['all'] = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(blog_id) as c FROM $wpdb->blogs WHERE site_id = %d", $id) );
     217        $count['spam'] = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(blog_id) as c FROM $wpdb->blogs WHERE site_id = %d AND spam = '1'", $id) );
     218        $count['deleted'] = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(blog_id) as c FROM $wpdb->blogs WHERE site_id = %d AND deleted = '1'", $id) );
     219        $count['archived'] = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(blog_id) as c FROM $wpdb->blogs WHERE site_id = %d AND archived = '1'", $id) );
    229220
    230         $count = get_site_option( "blog_count" );
    231 
     221        $count = (object) $count;
     222        set_site_transient( "blog_count", $count );
     223       
    232224        return $count;
    233225}
    234226
     
    789781        update_user_option($user_id, 'user_level', '');
    790782
    791783        do_action( 'wpmu_new_user', $user_id );
     784       
     785        delete_site_transient( "user_count" );
    792786
    793787        return $user_id;
    794788}