PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Username of First name and first letter Last name

  1. Is it possible to assign a username to a new user using the First Name + 1st letter of the Surname? Like Robert R., I think I'm in the right direction using http://php.net/manual/en/function.substr.php
    but can't get it work. Any suggestions on this are welcome!

    <?php
           add_filter('gform_username', 'auto_username');
    function auto_username($username){
    
        $username = strtolower(rgpost('input_1_3') . $string[0];(rgpost('input_1_4')));
    
        if(empty($username))
            return $username;
    
        if(!function_exists('username_exists'))
            require_once(ABSPATH . WPINC . "/registration.php");
    
        if(username_exists($username)){
            $i = 2;
            while(username_exists($username . $i)){
                $i++;
            }
            $username = $username . $i;
        };
    
        return $username;
    }
    ?>
    Posted 11 years ago on Saturday January 5, 2013 | Permalink
  2. Line 05 should look more like this:

    [php]
    $username = strtolower(rgpost('input_1_3') . ' ' . substr(rgpost('input_1_6'), 0, 1));

    That assumes field 1 is your name field. If not, the 1_3 and 1_6 will need to change.

    Also, you said "Robert R" but this will create "robert r" since you are using strtolower.

    Posted 11 years ago on Saturday January 5, 2013 | Permalink