Ticket #22917: 22917.6.diff
File 22917.6.diff, 6.3 KB (added by , 11 years ago) |
---|
-
src/wp-admin/includes/ms.php
146 146 } 147 147 148 148 clean_blog_cache( $blog ); 149 150 wp_update_network_counts_maybe_update( 'sites' ); 149 151 } 150 152 151 153 if ( $switch ) … … 202 204 203 205 clean_user_cache( $user ); 204 206 207 wp_update_network_counts_maybe_update( 'users' ); 208 205 209 /** 206 210 * Fires after the user is deleted from the network. 207 211 * -
src/wp-includes/ms-functions.php
908 908 909 909 do_action( 'wpmu_new_user', $user_id ); 910 910 911 wp_update_network_counts_maybe_update( 'users' ); 912 911 913 return $user_id; 912 914 } 913 915 … … 1102 1104 1103 1105 $blog_id = $wpdb->insert_id; 1104 1106 refresh_blog_details( $blog_id ); 1107 wp_update_network_counts_maybe_update( 'sites' ); 1108 1105 1109 return $blog_id; 1106 1110 } 1107 1111 … … 1874 1878 * Update the network-wide counts for the current network. 1875 1879 * 1876 1880 * @since 3.1.0 1881 * 1882 * @uses wp_update_network_user_counts() 1883 * @uses wp_update_network_site_counts() 1877 1884 */ 1878 1885 function wp_update_network_counts() { 1886 wp_update_network_user_counts(); 1887 wp_update_network_site_counts(); 1888 } 1889 1890 /** 1891 * Update the network-wide counts for the current network. 1892 * 1893 * If enabled through the 'enable_live_network_counts' filter, update the sites or 1894 * users count on a network as the user or site is created. 1895 * 1896 * @since 3.7.0 1897 * 1898 * @uses wp_update_network_user_counts() 1899 * @uses wp_update_network_site_counts() 1900 */ 1901 function wp_update_network_counts_maybe_update( $context = 'sites' ) { 1902 /** 1903 * Filter the decision to update network user and site counts in real time. 1904 * 1905 * @since 3.7.0 1906 * 1907 * @param bool null Opposite of wp_is_large_network() result. Depending on context, 1908 * either 'users' or 'sites' will be passed to wp_is_large_network(). 1909 * @param string null Context. Either 'users' or 'sites'. 1910 */ 1911 if ( ! apply_filters( 'enable_live_network_counts', ! wp_is_large_network( $context ), $context ) ) 1912 return; 1913 1914 if ( 'sites' === $context ) 1915 wp_update_network_site_counts(); 1916 1917 if ( 'users' === $context ) 1918 wp_update_network_user_counts(); 1919 1920 return; 1921 } 1922 1923 /** 1924 * Update the network-wide user count. 1925 * 1926 * @since 3.7.0 1927 */ 1928 function wp_update_network_user_counts() { 1879 1929 global $wpdb; 1880 1930 1881 $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) );1882 update_site_option( 'blog_count', $count );1883 1884 1931 $count = $wpdb->get_var( "SELECT COUNT(ID) as c FROM $wpdb->users WHERE spam = '0' AND deleted = '0'" ); 1885 1932 update_site_option( 'user_count', $count ); 1886 1933 } 1887 1934 1888 1935 /** 1936 * Update the network-wide site count. 1937 * 1938 * @since 3.7.0 1939 */ 1940 function wp_update_network_site_counts() { 1941 global $wpdb; 1942 1943 $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 ) ); 1944 update_site_option( 'blog_count', $count ); 1945 } 1946 1947 /** 1889 1948 * Returns the space used by the current blog. 1890 1949 * 1891 1950 * @since 3.5.0 -
src/wp-includes/user.php
1434 1434 wp_cache_delete($user_id, 'users'); 1435 1435 wp_cache_delete($user_login, 'userlogins'); 1436 1436 1437 if ( is_multisite() ) 1438 wp_update_network_counts_maybe_update( 'users' ); 1439 1437 1440 if ( $update ) 1438 1441 do_action('profile_update', $user_id, $old_user_data); 1439 1442 else -
tests/phpunit/tests/ms.php
16 16 $_SERVER['REMOTE_ADDR'] = ''; 17 17 } 18 18 19 /** 20 * @ticket 22917 21 */ 22 function test_enable_live_network_site_counts_filter() { 23 $site_count_start = get_blog_count(); 24 add_filter( 'enable_live_network_counts', __return_false ); //false by default as of 3.7 25 $this->factory->blog->create_many( 4 ); 26 27 $this->assertEquals( $site_count_start, (int) get_blog_count() ); //count only updated when cron runs, so likely unchanged 28 29 add_filter( 'enable_live_network_counts', __return_true ); //turns on live updating 30 $site_ids = $this->factory->blog->create_many( 4 ); 31 32 $this->assertEquals( $site_count_start + 9, (int) get_blog_count() ); //count should be updated 33 34 //clean up 35 remove_filter( 'enable_live_network_counts', __return_false ); 36 remove_filter( 'enable_live_network_counts', __return_true ); 37 foreach ( $site_ids as $site_id ) { 38 wpmu_delete_blog( $site_id, true ); 39 } 40 } 41 42 /** 43 * @ticket 22917 44 */ 45 function test_enable_live_network_user_counts_filter() { 46 add_filter( 'enable_live_network_counts', __return_false ); //false by default as of 3.7 47 48 // Refresh the cache 49 wp_update_network_counts(); 50 $start_count = get_user_count(); 51 52 wpmu_create_user( 'user', 'pass', 'email' ); 53 54 $count = get_user_count(); // No change, cache not refreshed 55 56 $this->assertEquals( $start_count, $count ); 57 58 //start over with filter on 59 wp_update_network_counts(); 60 $start_count = get_user_count(); 61 62 add_filter( 'enable_live_network_counts', __return_true ); //turns on live updating 63 64 wpmu_create_user( 'user2', 'pass2', 'email2' ); 65 66 $count = get_user_count(); 67 $this->assertEquals( $start_count + 1, $count ); 68 69 //turn filter back off 70 remove_filter( 'enable_live_network_counts', __return_false ); 71 remove_filter( 'enable_live_network_counts', __return_true ); 72 } 73 19 74 function test_create_and_delete_blog() { 20 75 global $wpdb; 21 76 … … 230 285 wp_update_network_counts(); 231 286 $start_count = get_user_count(); 232 287 288 add_filter( 'enable_live_network_counts', __return_false ); //false by default as of 3.7 233 289 $this->factory->user->create( array( 'role' => 'administrator' ) ); 234 290 235 291 $count = get_user_count(); // No change, cache not refreshed … … 239 295 240 296 $count = get_user_count(); 241 297 $this->assertEquals( $start_count + 1, $count ); 298 remove_filter( 'enable_live_network_counts', __return_false ); 242 299 } 243 300 244 301 function test_wp_schedule_update_network_counts() {