sync wpmu names with bp-xprofile.
-
Here’s a piece of code I wrote to sync the
-name (core field)
-last name (custom field)
-first name (custom field)
from BP with WPMU :
-BP name becomes WPMU display name
-BP first name becomes WPMU first name
-BP last name becomes WPMU last name
You have to create those 2 fields in the xprofile admin; then set their ids in the functions
$first_name_field_id=…;
$name_field_id=…;
They have to be set in the BASE group of xprofile (group id #1).
function sync_wp_bp_names() {
global $bp;
if (bp_get_current_profile_group_id()!=1) return false;
require_once( ABSPATH . WPINC . ‘/registration.php’);
$user = new WP_User($bp->displayed_user->id);
$first_name_field_id=40;
$name_field_id=39;
//DISPLAY NAME == BP NAME
if ( isset( $_POST[‘field_1’] ))
$user->display_name = esc_html( trim( $_POST[‘field_1’] ));
//FIRST NAME
if ( isset( $_POST[‘field_’.$first_name_field_id] ))
$user->first_name = esc_html( trim( $_POST[‘field_’.$first_name_field_id] ));
//LAST NAME
if ( isset( $_POST[‘field_’.$name_field_id] ))
$user->last_name = esc_html( trim( $_POST[‘field_’.$name_field_id] ));
wp_update_user( get_object_vars( $user ) );
}
add_action( ‘xprofile_updated_profile’, ‘sync_wp_bp_names’ );
What do you think of that ?
I also don’t understand the differences between display name and nicename in WPMU…
- The topic ‘sync wpmu names with bp-xprofile.’ is closed to new replies.