Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /** With WPUF it's better to set the profile update functions priority high **/
- /** Alternative solution as this plugin - https://wordpress.org/plugins/force-first-last/ **/
- /* First name & last name as default display name. */
- add_action( 'profile_update', 'set_display_name', 20 );
- function set_display_name( $user_id ) {
- $data = get_userdata( $user_id );
- if($data->first_name) {
- remove_action( 'profile_update', 'set_display_name', 10 ); // profile_update is called by wp_update_user, so we need to remove it before call, to avoid infinite recursion
- wp_update_user(
- array (
- 'ID' => $user_id,
- 'display_name' => "$data->first_name $data->last_name"
- )
- );
- add_action( 'profile_update', 'set_display_name', 20 ); // set the priority high to override other plugins
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement