Make WordPress Core


Ignore:
Timestamp:
09/25/2013 04:20:21 PM (11 years ago)
Author:
nacin
Message:

Live network counts of users and sites for small networks.

props adamsilverstein, jeremyfelt.
fixes #22917.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/ms-functions.php

    r25590 r25621  
    11031103    $blog_id = $wpdb->insert_id;
    11041104    refresh_blog_details( $blog_id );
     1105
     1106    wp_maybe_update_network_site_counts();
     1107
    11051108    return $blog_id;
    11061109}
     
    18771880 */
    18781881function wp_update_network_counts() {
     1882    wp_update_network_user_counts();
     1883    wp_update_network_site_counts();
     1884}
     1885
     1886/**
     1887 * Update the count of sites for the current network.
     1888 *
     1889 * If enabled through the 'enable_live_network_counts' filter, update the sites count
     1890 * on a network when a site is created or its status is updated.
     1891 *
     1892 * @since 3.7.0
     1893 *
     1894 * @uses wp_update_network_site_counts()
     1895 */
     1896function wp_maybe_update_network_site_counts() {
     1897    $is_small_network = ! wp_is_large_network( 'sites' );
     1898
     1899    /**
     1900     * Filter the decision to update network user and site counts in real time.
     1901     *
     1902     * @since 3.7.0
     1903     *
     1904     * @param bool   $small_network Based on wp_is_large_network( $context ).
     1905     * @param string $context       Context. Either 'users' or 'sites'.
     1906     */
     1907    if ( ! apply_filters( 'enable_live_network_counts', $is_small_network, 'sites' ) )
     1908        return;
     1909
     1910    wp_update_network_site_counts();
     1911}
     1912
     1913/**
     1914 * Update the network-wide users count.
     1915 *
     1916 * If enabled through the 'enable_live_network_counts' filter, update the users count
     1917 * on a network when a user is created or its status is updated.
     1918 *
     1919 * @since 3.7.0
     1920 *
     1921 * @uses wp_update_network_user_counts()
     1922 */
     1923function wp_maybe_update_network_user_counts() {
     1924    $is_small_network = ! wp_is_large_network( 'users' );
     1925
     1926    /**
     1927     * Filter the decision to update network user and site counts in real time.
     1928     *
     1929     * @since 3.7.0
     1930     *
     1931     * @param bool   $small_network Based on wp_is_large_network( $context ).
     1932     * @param string $context       Context. Either 'users' or 'sites'.
     1933     */
     1934    if ( ! apply_filters( 'enable_live_network_counts', $is_small_network, 'users' ) )
     1935        return;
     1936
     1937    wp_update_network_user_counts();
     1938}
     1939
     1940/**
     1941 * Update the network-wide site count.
     1942 *
     1943 * @since 3.7.0
     1944 */
     1945function wp_update_network_site_counts() {
    18791946    global $wpdb;
    18801947
    18811948    $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) );
    18821949    update_site_option( 'blog_count', $count );
     1950}
     1951
     1952/**
     1953 * Update the network-wide user count.
     1954 *
     1955 * @since 3.7.0
     1956 */
     1957function wp_update_network_user_counts() {
     1958    global $wpdb;
    18831959
    18841960    $count = $wpdb->get_var( "SELECT COUNT(ID) as c FROM $wpdb->users WHERE spam = '0' AND deleted = '0'" );
Note: See TracChangeset for help on using the changeset viewer.