WordPress.org

Make WordPress Core

Ticket #12531: onlyimprove.patch

File onlyimprove.patch, 3.1 KB (added by ocean90, 8 years ago)
  • 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-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-functions.php

     
    99        global $wpdb;
    1010
    1111        $stats['blogs'] = get_blog_count();
     12        $stats['users'] = get_user_count();
    1213
    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
     
    202194function get_user_count() {
    203195        global $wpdb;
    204196
    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         }
     197        $count = get_site_transient( 'user_count' );
    211198
    212         $count = get_site_option( "user_count" );
     199        if ( false !== $count )
     200                return $count;
    213201
     202        $count = $wpdb->get_var( "SELECT COUNT(ID) as c FROM $wpdb->users WHERE spam = '0' AND deleted = '0'" );
     203
     204        set_site_transient( 'user_count', $count );
     205
    214206        return $count;
    215207}
    216208
     
    220212        if ( $id == 0 )
    221213                $id = $wpdb->siteid;
    222214
    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         }
     215        $count = get_site_transient( 'user_count' );
    229216
    230         $count = get_site_option( "blog_count" );
     217        if ( false !== $count )
     218                return $count;
    231219
     220        $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' AND mature = '0'", $id) );
     221
     222        set_site_transient( 'blog_count', $count );
     223
    232224        return $count;
    233225}
    234226
     
    836828
    837829        restore_current_blog();
    838830        do_action( 'wpmu_new_blog', $blog_id, $user_id );
    839 
     831       
     832        delete_site_transient( 'user_count' );
     833       
    840834        return $blog_id;
    841835}
    842836