User Profile and display_name

Support MB User Profile User Profile and display_nameResolved

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #17120
    pzapza
    Participant

    I've added a field group with a text field, ID = display_name as indicated here:
    https://support.metabox.io/topic/duplicate-fields-on-the-backend

    But when a profile is edited using MB user profile, it saves the field value only.

    The user display name is not updated. Is there another ID or process required to make display_name work? Thank you

    #17655
    pzapza
    Participant

    I never could figure this out. User "display name" can not be updated via user profile?

    #17670
    Anh TranAnh Tran
    Keymaster

    Hi pza, sorry for the delay. At the moment, it's not possible yet, because display_name is not a custom user meta. It's a field in the users table. I'll update the plugin to support it and all user fields.

    #18017
    pzapza
    Participant

    By the way in case it helps anyone, here's what I ended up doing:

    • custom text field named display_name in user profile
    • for user profile, a field group with ID user-profile
    • the following code to update user info after saving the MB profile
    add_action( 'rwmb_profile_after_process', function( $config, $user_id ) {
        if ( $config['id'] == 'user-profile' ) {
            if ( $uname = $_POST['display_name'] ) {
                $args = array(
                    'ID' => $user_id,
                    'display_name' => $uname
                );
                $update = wp_update_user($args);
            }
        }
    }, 10, 2 );
    • and this to update the default profile field value in case it was changed elsewhere (ie. Edit account page)
    add_filter( 'rwmb_display_name_field_meta', function( $meta, $field, $saved ) {
        $current_user = wp_get_current_user();
        return $current_user->display_name;
    }, 10, 3 );
    #19328
    Anh TranAnh Tran
    Keymaster

    I've added support for display_name and other user fields in version 1.7.0. Thanks @pza for your suggestion.

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.