p2_get_at_name_map

The BP Groupblog p2 get at name map function.

Description

p2_get_at_name_map(); 

Usage

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

Defined (1)

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

/themes/p2/functions.php  
  1. function p2_get_at_name_map() { 
  2. global $wpdb; 
  3. static $name_map = array(); 
  4. if ( $name_map ) // since $names is static, the stuff below will only get run once per page load. 
  5. return $name_map; 
  6. $users = get_users_of_blog(); 
  7. // get display names (can take out if you only want to handle nicenames) 
  8. foreach ( $users as $user ) { 
  9. $name_map["@$user->user_login"]['id'] = $user->ID; 
  10. $users_to_array[] = $user->ID; 
  11. // get nicenames (can take out if you only want to handle display names) 
  12. $user_ids = join( ', ', array_map( 'intval', $users_to_array ) ); 
  13.  
  14. foreach ( $wpdb->get_results( "SELECT ID, display_name, user_nicename from $wpdb->users WHERE ID IN($user_ids)" ) as $user ) { 
  15. $name_map["@$user->display_name"]['id'] = $user->ID; 
  16. $name_map["@$user->user_nicename"]['id'] = $user->ID; 
  17.  
  18. foreach ( $name_map as $name => $values) { 
  19. $username = get_userdata( $values['id'] )->user_login; 
  20. $name_map[$name]['replacement'] = '<a href="' . esc_url( '/mentions/' . $username ) . '/">' . esc_html( $name ) . '</a>'; 
  21.  
  22. // remove any empty name just in case 
  23. unset( $name_map['@'] ); 
  24. return $name_map;