Last active
January 31, 2018 19:35
-
-
Save phoopee3/69e991f08eb595efdaedb7a02bc0e8ef to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function updateUserNicename( $user_id, $posted_field_ids, $errors, $old_values, $new_values ) | |
{ | |
$old_nicename = wp_cache_get( 'bp_user_username_' . $user_id, 'bp' ); | |
if ( empty( $errors ) ) { | |
// update user_nicename | |
// field 2 = first name | |
// field 3 = last name | |
$new_nicename = $new_values[2]['value'] . '-' . $new_values[3]['value']; | |
// update user_nicename | |
$updated = wp_update_user( array( 'ID' => $user_id, 'user_nicename' => $new_nicename ) ); | |
if ( is_wp_error( $updated ) ) { | |
die($updated); | |
} else { | |
$new_nicename = get_userdata( $user_id )->user_nicename; | |
// wp_cache_delete( 'bp_user_username_' . $user_id, 'bp' ); | |
// wp_cache_delete( 'bp_core_userdata_' . $user_id, 'bp' ); | |
wp_cache_replace( 'bp_user_username_' . $user_id, $new_nicename, 'bp' ); | |
} | |
} | |
$bp = buddypress(); | |
$bp->displayed_user->domain = str_replace( $old_nicename, $new_nicename, $bp->displayed_user->domain ); | |
} | |
add_action('xprofile_updated_profile', 'updateUserNicename', 1, 5 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment