Skip to:

How to run xprofile_sync_wp_profile() on registration

  • peterverkooijen


    Can anyone please tell me how to run xprofile_sync_wp_profile() on registration?

    xprofile_sync_wp_profile() splits first_name and last_name from BP’s fullname registration field and stores them in WordPress’ standard usermeta table. That is tremendously useful, if you can count on that data being there.

    I’ve tried putting the function in a plugin to run on user_register as action hook, but got a “cannot redeclare” error because the function is already in bp-xprofile-filters.php.

    I’ve tried editing the add_action thingy in that file from xprofile_updated_profile to user_register, but it had no effect.

    I can’t find any more documentation on how to use this function.

    Any pointers very much appreciated!

    Edit: As far as I understand this function now only kicks in when the user updates his profile:

    add_action( 'xprofile_updated_profile', 'xprofile_sync_wp_profile' );

    That could be never, so you can never count on that first_name, last_name data being there in wp_usermeta. In my case I need first_name, last_name “somewhere” for synchronisation with ListMessenger mailing list. There are many other scenarios where you’d need them.

    Replacing xprofile_updated_profile with user_register did not work. Should I try other hooks? Which ones? Or am I on the wrong track? Does the ‘$bp->loggedin_user->id’ line make it impossible to run this function on registration? How about on first login? Is there a hook for that?

    Also, if I can get this to work, it looks like a small step to include a few lines to autogenerate a username from the full name.

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

  • peterverkooijen


    I guess function xprofile_sync_wp_profile() requires that the fullname (BP_XPROFILE_FULLNAME_FIELD_NAME) is already in the database and that the function can only be run after the user is already logged in.

    So I guess I need to write another function that takes the fullname straight from the registration form and can be run with the user_register hook.

    Where can I find the functions that take the data from the registration form and store them? I could probably use them as examples to come up with my own fuction for a plugin.

    Edit: I guess all the magic happens in bp-xprofile-signup.php (function xprofile_load_signup_meta())? Is there a way to add a x-profile/wp_usermeta synchronization function to that file?



    Data from the fullname field on the registration form is apparently stored in x-profile via this line:

    // put the user profile meta in a session ready to store.
    for ( $i = 0; $i < count($bp_xprofile_callback); $i++ ) {
    $bp_user_signup_meta['field_' . $bp_xprofile_callback[$i]['field_id']] .= $bp_xprofile_callback[$i]['value'];

    How can I put the value from the fullname field into a function that does the same thing as xprofile_sync_wp_profile()?

    I’d have to replace the BP_XPROFILE_FULLNAME_FIELD_NAME line with “something”. The fullname field_id seems to be 1.

    So something like this?:

    $bp_user_signup_meta['field_' . $bp_xprofile_callback['1'] .= $bp_xprofile_callback['value'];




    This plugin attempt doesn’t break anything, but still doesn’t put first_name and last_name in wp_usermeta either:




    Plugin Name: Real Name Synchro

    Plugin URI: http://

    Version: v0.001

    Author: peterverkooijen

    Description: A plugin to store firstname and lastname from the fullname field in Buddypress registration in WPMU usermeta tables.


    function real_name_synchro() {

    global $bp, $wpdb, $bp_user_signup_meta;

    $fields = BP_XProfile_Field::get_signup_fields();

    if ( $fields ) {

    foreach ( $fields as $field ) {

    $value = $_POST[‘field_’ . $field->id];



    $field->id = ‘1’;

    $fullname = $value;

    $space = strpos( $fullname, ‘ ‘ );

    if ( false === $space ) {

    $firstname = $fullname;

    $lastname = ”;

    } else {

    $firstname = substr( $fullname, 0, $space );

    $lastname = trim( substr( $fullname, $space, strlen($fullname) ) );


    update_usermeta( $user_id, ‘nickname’, $fullname );

    update_usermeta( $user_id, ‘first_name’, $firstname );

    update_usermeta( $user_id, ‘last_name’, $lastname );

    $wpdb->query( $wpdb->prepare( “UPDATE {$wpdb->users} SET display_name = %s WHERE ID = %d”, $fullname, $user_id ) );

    $wpdb->query( $wpdb->prepare( “UPDATE {$wpdb->users} SET user_url = %s WHERE ID = %d”, bp_core_get_user_domain( $user_id ), $user_id ) );



    add_action(‘user_register’, ‘real_name_synchro’);



    Can anyone suggest fixes or am I fundamentally on the wrong track?

    Suzan Jasmin O.


    I have the latest Wp and latest BuddyPress 1.9.2
    On the new user registration form it has FULL NAME box
    But I need FIRST NAME and LAST NAME boxes. So I can in admin panel and users on frontend can register new users can fill their names with 2 boxes. And on search page users can search other users by first name or last name. And I can hide last names for some users etc.. Its always convenient to have first and last names in separate DB columns. So please help me out, how can I have the BuddyPress plugged site of mine to function like above?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to run xprofile_sync_wp_profile() on registration’ is closed to new replies.
Skip to toolbar