diff --git src/wp-includes/user.php src/wp-includes/user.php
index d02b022..3181921 100644
|
|
|
function count_users($strategy = 'time') { |
| 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; |
| … |
… |
function count_users($strategy = 'time') { |
| 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); |
diff --git tests/phpunit/tests/user/countUsers.php tests/phpunit/tests/user/countUsers.php
index d3192bb..b998d5e 100644
|
|
|
class Tests_User_CountUsers extends WP_UnitTestCase { |
| 186 | 186 | ); |
| 187 | 187 | } |
| 188 | 188 | |
| | 189 | /** |
| | 190 | * @ticket 29785 |
| | 191 | */ |
| | 192 | public function test_should_not_count_users_who_are_not_in_posts_table_memory() { |
| | 193 | global $wpdb; |
| | 194 | |
| | 195 | // Get a 'before' count for comparison. |
| | 196 | $count = count_users( 'memory' ); |
| | 197 | |
| | 198 | $u = self::factory()->user->create( array( 'role' => 'editor' ) ); |
| | 199 | |
| | 200 | // Manually delete the user, but leave the capabilities usermeta. |
| | 201 | $wpdb->delete( $wpdb->users, array( 'ID' => $u ) ); |
| | 202 | |
| | 203 | $count2 = count_users( 'memory' ); |
| | 204 | |
| | 205 | $this->assertEqualSets( $count, $count2 ); |
| | 206 | } |
| | 207 | /** |
| | 208 | * @ticket 29785 |
| | 209 | */ |
| | 210 | public function test_should_not_count_users_who_are_not_in_posts_table_time() { |
| | 211 | global $wpdb; |
| | 212 | |
| | 213 | // Get a 'before' count for comparison. |
| | 214 | $count = count_users( 'time' ); |
| | 215 | |
| | 216 | $u = self::factory()->user->create( array( 'role' => 'editor' ) ); |
| | 217 | |
| | 218 | // Manually delete the user, but leave the capabilities usermeta. |
| | 219 | $wpdb->delete( $wpdb->users, array( 'ID' => $u ) ); |
| | 220 | |
| | 221 | $count2 = count_users( 'time' ); |
| | 222 | |
| | 223 | $this->assertEqualSets( $count, $count2 ); |
| | 224 | } |
| 189 | 225 | } |