WordPress.org

Make WordPress Core

Ticket #12531: 12531.6.2.patch

File 12531.6.2.patch, 4.1 KB (added by ocean90, 8 years ago)
  • wp-admin/includes/ms.php

     
    7676
    7777        update_blog_status( $blog_id, 'deleted', 1 );
    7878
     79        delete_site_transient( 'blog_count' );
     80
    7981        if ( $drop ) {
    8082                $drop_tables = $wpdb->get_results( "SHOW TABLES LIKE '{$blog_prefix}%'", ARRAY_A );
    8183                $drop_tables = apply_filters( 'wpmu_drop_tables', $drop_tables );
     
    167169        $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->usermeta WHERE user_id = %d", $id ) );
    168170
    169171        clean_user_cache( $id );
     172       
     173        delete_site_transient( 'user_count' );
    170174
    171175        // allow for commit transaction
    172176        do_action( 'deleted_user', $id );
     
    528532                        do_action( 'make_ham_user', $id );
    529533        }
    530534
     535        delete_site_transient( 'user_count' );
     536
    531537        return $value;
    532538}
    533539
  • wp-includes/ms-blogs.php

     
    508508                        do_action( "make_ham_blog", $blog_id );
    509509        }
    510510
     511        delete_site_transient( 'blog_count' );
     512
    511513        return $value;
    512514}
    513515
  • wp-includes/ms-functions.php

     
    1111        global $wpdb;
    1212
    1313        $stats['blogs'] = get_blog_count();
     14        $stats['users'] = get_user_count();
    1415
    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;
    2416        return $stats;
    2517}
    2618
     
    204196function get_user_count() {
    205197        global $wpdb;
    206198
    207         $count_ts = get_site_option( "user_count_ts" );
    208         if ( time() - $count_ts > 3600 ) {
    209                 $count = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(ID) as c FROM $wpdb->users WHERE spam = '0' AND deleted = '0'") );
    210                 update_site_option( "user_count", $count );
    211                 update_site_option( "user_count_ts", time() );
    212         }
     199        $count = get_site_transient( 'user_count' );
     200        if ( false !== $count )
     201                return $count;
    213202
    214         $count = get_site_option( "user_count" );
    215 
    216         return $count;
     203        $count = $wpdb->get_var( "SELECT COUNT(ID) as c FROM $wpdb->users WHERE spam = '0' AND deleted = '0'" );
     204        set_site_transient( 'user_count', (int) $count );       
     205               
     206        return (int) $count;
    217207}
    218208
    219 function get_blog_count( $id = 0 ) {
     209function get_blog_count( $site_id = 0 ) {
    220210        global $wpdb;
    221211
    222         if ( $id == 0 )
    223                 $id = $wpdb->siteid;
     212        if ( $site_id == 0 )
     213                $site_id = $wpdb->siteid;
    224214
    225         $count_ts = get_site_option( "blog_count_ts" );
    226         if ( time() - $count_ts > 3600 ) {
    227                 $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) );
    228                 update_site_option( "blog_count", $count );
    229                 update_site_option( "blog_count_ts", time() );
    230         }
     215        $count = get_site_transient( 'blog_count' );
     216        if ( false !== $count )
     217                return $count;
     218       
     219        $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'", $site_id) );
     220        set_site_transient( 'blog_count', (int) $count );
    231221
    232         $count = get_site_option( "blog_count" );
    233 
    234         return $count;
     222        return (int) $count;
    235223}
    236224
    237225function get_blog_post( $blog_id, $post_id ) {
     
    786774                return false;
    787775
    788776        // Newly created users have no roles or caps until they are added to a blog.
    789         update_user_option($user_id, 'capabilities', '');
    790         update_user_option($user_id, 'user_level', '');
     777        delete_user_option($user_id, 'capabilities' );
     778        delete_user_option($user_id, 'user_level' );
    791779
    792780        do_action( 'wpmu_new_user', $user_id );
     781       
     782        delete_site_transient( 'user_count' );
    793783
    794784        return $user_id;
    795785}
     
    838828        restore_current_blog();
    839829        do_action( 'wpmu_new_blog', $blog_id, $user_id );
    840830
     831        delete_site_transient( 'blog_count' );
     832       
    841833        return $blog_id;
    842834}
    843835