Ticket #29785: 29785.4.diff
File 29785.4.diff, 2.0 KB (added by , 7 years ago) |
---|
-
src/wp-includes/user.php
857 857 $select_count = implode(', ', $select_count); 858 858 859 859 // Add the meta_value index to the selection list, then run the query. 860 $row = $wpdb->get_row( "SELECT $select_count, COUNT(*) FROM $wpdb->usermeta WHERE meta_key = '{$blog_prefix}capabilities'", ARRAY_N );860 $row = $wpdb->get_row( "SELECT $select_count, COUNT(*) FROM $wpdb->usermeta JOIN $wpdb->users ON user_id = ID WHERE meta_key = '{$blog_prefix}capabilities'", ARRAY_N ); 861 861 862 862 // Run the previous loop again to associate results with role names. 863 863 $col = 0; … … 881 881 'none' => 0, 882 882 ); 883 883 884 $users_of_blog = $wpdb->get_col( "SELECT meta_value FROM $wpdb->usermeta WHERE meta_key = '{$blog_prefix}capabilities'" );884 $users_of_blog = $wpdb->get_col( "SELECT meta_value FROM $wpdb->usermeta JOIN $wpdb->users ON user_id = ID WHERE meta_key = '{$blog_prefix}capabilities'" ); 885 885 886 886 foreach ( $users_of_blog as $caps_meta ) { 887 887 $b_roles = maybe_unserialize($caps_meta); -
tests/phpunit/tests/user/countUsers.php
186 186 ); 187 187 } 188 188 189 /** 190 * @ticket 29785 191 * 192 * @dataProvider data_count_users_strategies 193 */ 194 public function test_should_not_count_users_who_are_not_in_posts_table( $strategy ) { 195 global $wpdb; 196 197 // Get a 'before' count for comparison. 198 $count = count_users( $strategy ); 199 200 $u = self::factory()->user->create( array( 201 'role' => 'editor', 202 ) ); 203 204 // Manually delete the user, but leave the capabilities usermeta. 205 $wpdb->delete( $wpdb->users, array( 206 'ID' => $u, 207 ) ); 208 209 $count2 = count_users( $strategy ); 210 211 $this->assertEqualSets( $count, $count2 ); 212 } 213 189 214 }