WordPress.org

Make WordPress Core

Ticket #22917: 22917-2.diff

File 22917-2.diff, 2.6 KB (added by adamsilverstein, 5 years ago)

new patch adds filter to turn on live update

  • wp-includes/ms-functions.php

     
    923923        delete_user_option( $user_id, 'user_level' );
    924924
    925925        do_action( 'wpmu_new_user', $user_id );
     926        if ( apply_filters( 'enable_live_network_user_counts', false ) )
     927                wp_update_network_user_counts(); //user added, update network counts
    926928
    927929        return $user_id;
    928930}
     
    11511153        populate_options();
    11521154        populate_roles();
    11531155        $wp_roles->_init();
     1156        if ( apply_filters ( 'enable_live_network_blog_counts', false ) )
     1157                wp_update_network_blog_counts(); //new blog added, update network counts
    11541158
    11551159        $url = untrailingslashit( $url );
    11561160
     
    19251929 *  @since 3.1.0
    19261930 */
    19271931function wp_update_network_counts() {
     1932        wp_update_network_user_counts();
     1933        wp_update_network_blog_counts();
     1934}
     1935
     1936/**
     1937 * Update the network-wide counts for users
     1938 *
     1939 * @since 3.6
     1940 *
     1941 */
     1942function wp_update_network_user_counts() {
    19281943        global $wpdb;
    19291944
    1930         $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) );
    1931         update_site_option( 'blog_count', $count );
    1932 
    19331945        $count = $wpdb->get_var( "SELECT COUNT(ID) as c FROM $wpdb->users WHERE spam = '0' AND deleted = '0'" );
    19341946        update_site_option( 'user_count', $count );
    19351947}
    19361948
    19371949/**
     1950 * Update the network-wide counts for blogs
     1951 *
     1952 * @since 3.6
     1953 *
     1954 */
     1955function wp_update_network_blog_counts() {
     1956        global $wpdb;
     1957
     1958        $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) );
     1959        update_site_option( 'blog_count', $count );
     1960}
     1961
     1962/**
    19381963 * Returns the space used by the current blog.
    19391964 *
    19401965 * @since 3.5.0
  • wp-admin/includes/ms.php

     
    122122                }
    123123
    124124                clean_blog_cache( $blog );
    125         }
     125                if ( apply_filters( 'enable_live_network_blog_counts', false ) )
     126                        wp_update_network_blog_counts(); //blog deleted, update network counts
     127                }
    126128
    127129        if ( $switch )
    128130                restore_current_blog();
     
    171173        $wpdb->delete( $wpdb->users, array( 'ID' => $id ) );
    172174
    173175        clean_user_cache( $user );
     176        if ( apply_filters( 'enable_live_network_user_counts', false ) )
     177                wp_update_network_user_counts(); //user deleted, update network counts
    174178
    175179        // allow for commit transaction
    176180        do_action( 'deleted_user', $id );