Skip to:
Content
Pages
Categories
Search
Top
Bottom

Change “Name” Field to First & Last Name


  • Howdy_McGee
    Participant

    @howdy_mcgee

    So I see this is a pretty common request and I have searched it but most the thread I see on it are 3+ years old. Either telling me to remove it via javascript or hide it via CSS. I’ve even see a few trac tickets about it not being removed or can’t be removed. And a plugin mentioned a few times but it doesn’t seem promising.

    I find it hard to believe that there’s an unremovable field added that you cannot easily replace with a First and Last name field considering most social websites, forums, and communities I’ve joined ask for that upon registration instead of a strangely generic “Name” field.

    I’m hoping I’m just on the wrong track and it’s easier than I think. The core of the question is, what’s a compatible, long term way to switch out the “Name” field for a “First Name” and “Last Name” field?

Viewing 9 replies - 1 through 9 (of 9 total)

  • Henry Wright
    Moderator

    @henrywright

    There isn’t anything special about the “Name” field aside from it being required. You could treat the field as the member’s first name and set up a second field labelled “Surname”?


    Howdy_McGee
    Participant

    @howdy_mcgee

    Thanks for the reply, so you’re saying I should rename this field to “First Name” and create a secondary field for “Last Name” ? If there is nothing special about the field, is there a hook or filter where I can replace the field entirely and map them to first / last name fields in WordPress?


    Henry Wright
    Moderator

    @henrywright

    Thanks for the reply, so you’re saying I should rename this field to “First Name” and create a secondary field for “Last Name” ?

    That’s one approach you could take.

    If there is nothing special about the field, is there a hook or filter where I can replace the field entirely and map them to first / last name fields in WordPress?

    I think not unfortunately. You could request one be added by opening a ticket on Trac


    maccast
    Participant

    @maccast

    I was dealing with this problem too. It might not be exactly what you’re looking for, but in my case I just decided to hook into the BP signup, extract the full name, split it at the first space and then update the WordPress ‘first_name’ and ‘last_name’ user metadata fields with the results.

    Here is the code you can add to your functions.php or custom plug-in:

    // define the bp_core_signup_user callback 
    function ac_bp_core_signup_user( $user_id ) { 
        // make action magic happen here...
        $fullname = bp_get_member_profile_data( array( 'field' => 'Name', 'user_id' => $user_id ) );
       //split the full name at the first space
       $name_parts = explode(" ", $fullname, 2);
    
       //set the firstname and lastname for WordPress based on the BP name
       //firstname
       if( isset($name_parts[0]) )
            update_user_meta( $user_id, 'first_name', $name_parts[0] );
    
       //lastname
       if( isset($name_parts[1]) )
           update_user_meta( $user_id, 'last_name', $name_parts[1] );
    
       //not needed for an action, but I always like to return something
       return $fullname;
    }
    
    // BuddyPress save first name last name to WP profile on signup 
    add_action( 'bp_core_signup_user', 'ac_bp_core_signup_user', 10, 1 );

    0x001
    Participant

    @0x001

    Nice


    Howdy_McGee
    Participant

    @howdy_mcgee

    That’s a good idea! The problem I forsee with that is they may not enter a last name and I’m trying to run the social part of the site with a first name / last name basis as I’ve seen in communities there’s less trolling and more politeness whenever your first / last name is out there.

    Of course this doesn’t stop people from enter faux content but it’s a start. Connecting with Facebook / Google also helps. This is just a piece of the puzzle which it turns out unfortunately must be rotated. I did bookmark it for the hook though, that’ll come in handy!


    Henry Wright
    Moderator

    @henrywright

    The problem with bp_core_signup_user is it’s executed during registration only. If a member decides to change their “Name” at a later date, I don’t think the corresponding WordPress fields will be updated.


    maccast
    Participant

    @maccast

    Good point @henrywright. In our case it may not matter too much since for us this is only so we see a name in the admin interface. On the front end we are only using the xprofile name. Still is there possibly another hook that I could tie into that runs on user profile update?


    Henry Wright
    Moderator

    @henrywright

    There sure is: xprofile_field_after_save

    Let me know if you need anything else.

Viewing 9 replies - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.
Skip to toolbar