bp_core_get_active_member_count

Return the total number of members, limited to those members with last_activity.

Description

(int) bp_core_get_active_member_count(); 

Returns (int)

The number of active members.


Usage

  1. if ( !function_exists( 'bp_core_get_active_member_count' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-members/bp-members-functions.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = bp_core_get_active_member_count(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/bp-members/bp-members-functions.php  
  1. function bp_core_get_active_member_count() { 
  2. global $wpdb; 
  3.  
  4. $count = get_transient( 'bp_active_member_count' ); 
  5. if ( false === $count ) { 
  6. $bp =buddypress); 
  7.  
  8. // Avoid a costly join by splitting the lookup. 
  9. if ( is_multisite() ) { 
  10. $sql = "SELECT ID FROM {$wpdb->users} WHERE (user_status != 0 OR deleted != 0 OR user_status != 0)"; 
  11. } else { 
  12. $sql = "SELECT ID FROM {$wpdb->users} WHERE user_status != 0"; 
  13.  
  14. $exclude_users = $wpdb->get_col( $sql ); 
  15. $exclude_users_sql = !empty( $exclude_users ) ? "AND user_id NOT IN (" . implode( ', ', wp_parse_id_list( $exclude_users ) ) . ")" : ''; 
  16. $count = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(user_id) FROM {$bp->members->table_name_last_activity} WHERE component = %s AND type = 'last_activity' {$exclude_users_sql}", $bp->members->id ) ); 
  17.  
  18. set_transient( 'bp_active_member_count', $count ); 
  19.  
  20. /** 
  21. * Filters the total number of members for the installation limited to those with last_activity. 
  22. * @since 1.6.0 
  23. * @param int $count Total number of active members. 
  24. */