// Build a CPU-intensive query that will return concise information.
$select_count = array
();
foreach ( $avail_roles as $this_role =>
$name ) { $select_count[] =
$wpdb->
prepare( 'COUNT(NULLIF(`meta_value` LIKE %s, false))', '%' .
$wpdb->
esc_like( '"' .
$this_role . '"'
) . '%'
);
} $select_count[] = "COUNT(NULLIF(`meta_value` = 'a:0:{}', false))";
$select_count =
implode( ', ',
$select_count );
// Add the meta_value index to the selection list, then run the query.
$row =
$wpdb->
get_row( "
SELECT {
$select_count}, COUNT(*)
FROM {
$wpdb->usermeta
}
INNER JOIN {
$wpdb->users
} ON user_id = ID
WHERE meta_key = '{
$blog_prefix}capabilities'
",
ARRAY_N
);
// Run the previous loop again to associate results with role names.
$col = 0;