jfb_pretty_username

The WP-FB-AutoConnect jfb pretty username function.

Description

jfb_pretty_username( $wp_userdata, $fb_userdata ); 

Parameters (2)

0. $wp_userdata
The wp userdata.
1. $fb_userdata
The fb userdata.

Usage

  1. if ( !function_exists( 'jfb_pretty_username' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'wp-fb-autoconnect/Main.php'; 
  3.  
  4. // The wp userdata. 
  5. $wp_userdata = null; 
  6.  
  7. // The fb userdata. 
  8. $fb_userdata = null; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = jfb_pretty_username($wp_userdata, $fb_userdata); 
  12.  

Defined (1)

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

/Main.php  
  1. function jfb_pretty_username( $wp_userdata, $fb_userdata ) 
  2. global $jfb_log, $opt_jfb_username_style; 
  3. $jfb_log .= "WP: Converting username to \"pretty\" username...\n"; 
  4.  
  5. //Create a username from the user's Facebook name 
  6. if( get_option($opt_jfb_username_style) == 1 ) 
  7. $name = "FB_" . str_replace( ' ', '', $fb_userdata['first_name'] . "_" . $fb_userdata['last_name'] ); 
  8. else if( get_option($opt_jfb_username_style) == 2 ) 
  9. $name = str_replace( ' ', '', $fb_userdata['first_name'] . "." . $fb_userdata['last_name'] ); 
  10. else 
  11. $name = str_replace( ' ', '', $fb_userdata['first_name'] . "_" . $fb_userdata['last_name'] ); 
  12.  
  13. //Strip all non-alphanumeric characters, and make sure we've got something left. If not, we'll just leave the FB_xxxxx username as is. 
  14. $name = sanitize_user($name, true); 
  15. if( strlen($name) <= 1 || $name == "FB__" ) 
  16. $jfb_log .= "WP: Warning - Completely non-alphanumeric Facebook name cannot be used; leaving as default.\n"; 
  17. return $wp_userdata; 
  18.  
  19. //Make sure the name is unique: if we've already got a user with this name, append a number to it. 
  20. $counter = 1; 
  21. if ( username_exists( $name ) ) 
  22. do 
  23. $username = $name; 
  24. $counter++; 
  25. $username = $username . $counter; 
  26. } while ( username_exists( $username ) ); 
  27. else 
  28. $username = $name; 
  29.  
  30. //Done! 
  31. $wp_userdata['user_login'] = $username; 
  32. $wp_userdata['user_nicename']= $username; 
  33. $jfb_log .= "WP: Name successfully converted to $username.\n"; 
  34. return $wp_userdata;