count_users ( $strategy = 'time', $site_id = null )

  • (string) strategy Optional. The computational strategy to use when counting the users. Accepts either 'time' or 'memory'. Default 'time'.
  • (int|null) site_id Optional. The site ID to count users for. Defaults to the current site.
  • (array) { User counts. @type int $total_users Total number of users on the site. @type int[] $avail_roles Array of user counts keyed by user role. }
Defined at:
Change Log:
  • 4: .
  • 4: .


Counts number of users who have each of the user roles.Assumes there are neither duplicated nor orphaned capabilities meta_values. Assumes role names are unique phrases. Same assumption made by WP_User_Query::prepare_query() Using $strategy = 'time' this is CPU-intensive and should handle around 10^7 users. Using $strategy = 'memory' this is memory-intensive and should handle around 10^5 users, but see WP Bug #12257.

Related Functions

count_user_posts, wp_count_terms, wp_count_sites, get_users, current_user_can

Top Google Results

User discussions

wpseek mobile