Ticket #22917: 22917.5.diff
File 22917.5.diff, 5.1 KB (added by , 11 years ago) |
---|
-
src/wp-admin/includes/ms.php
146 146 } 147 147 148 148 clean_blog_cache( $blog ); 149 150 //duplicate hook 151 if ( apply_filters( 'enable_live_network_counts', ! wp_is_large_network( 'sites' ), 'sites' ) ) 152 wp_update_network_site_counts(); 149 153 } 150 154 151 155 if ( $switch ) … … 202 206 203 207 clean_user_cache( $user ); 204 208 209 //duplicate hook 210 if ( apply_filters( 'enable_live_network_counts', ! wp_is_large_network( 'users' ), 'users' ) ) 211 wp_update_network_user_counts(); 212 205 213 /** 206 214 * Fires after the user is deleted from the network. 207 215 * -
src/wp-includes/ms-functions.php
908 908 909 909 do_action( 'wpmu_new_user', $user_id ); 910 910 911 /** 912 * Filter the decision to update network user and site counts in real time. 913 * 914 * @since 3.7.0 915 * 916 * @param bool null Opposite of wp_is_large_network() result. Depending on context, 917 * either 'users' or 'sites' will be passed to wp_is_large_network(). 918 * @param string null Context. Either 'users' or 'sites'. 919 */ 920 if ( apply_filters( 'enable_live_network_counts', ! wp_is_large_network( 'users' ), 'users' ) ) 921 wp_update_network_user_counts(); 922 911 923 return $user_id; 912 924 } 913 925 … … 1140 1152 populate_roles(); 1141 1153 $wp_roles->_init(); 1142 1154 1155 //duplicate hook 1156 if ( apply_filters( 'enable_live_network_counts', ! wp_is_large_network( 'sites' ), 'sites' ) ) 1157 wp_update_network_site_counts(); 1158 1143 1159 $url = untrailingslashit( $url ); 1144 1160 1145 1161 update_option( 'siteurl', $url ); … … 1874 1890 * Update the network-wide counts for the current network. 1875 1891 * 1876 1892 * @since 3.1.0 1893 * 1894 * @uses wp_update_network_user_counts() 1895 * @uses wp_update_network_site_counts() 1877 1896 */ 1878 1897 function wp_update_network_counts() { 1898 wp_update_network_user_counts(); 1899 wp_update_network_site_counts(); 1900 } 1901 1902 /** 1903 * Update the network-wide user count. 1904 * 1905 * @since 3.7.0 1906 */ 1907 function wp_update_network_user_counts() { 1879 1908 global $wpdb; 1880 1909 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 1910 $count = $wpdb->get_var( "SELECT COUNT(ID) as c FROM $wpdb->users WHERE spam = '0' AND deleted = '0'" ); 1885 1911 update_site_option( 'user_count', $count ); 1886 1912 } 1887 1913 1888 1914 /** 1915 * Update the network-wide site count. 1916 * 1917 * @since 3.7.0 1918 */ 1919 function wp_update_network_site_counts() { 1920 global $wpdb; 1921 1922 $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 ) ); 1923 update_site_option( 'blog_count', $count ); 1924 } 1925 1926 /** 1889 1927 * Returns the space used by the current blog. 1890 1928 * 1891 1929 * @since 3.5.0 -
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