Skip to:
Content
Pages
Categories
Search
Top
Bottom

Allow for basic user profiles in buddypress profile edit


  • lunarca
    Participant

    @lunarca

    Hey there!

    I have a quite simple dilemma but can’t quite get it right. I am trying to set up the extended profile for users but I’d like for some of the basic profile fields from a standard WordPress installation to show and be edited through it.

    Especifically I’d like to have the first name, last name, url and user description, that are available trough the wp-admin/profile.php dashboard page, to be editable through the <site>/members/<user nicename>/profile/edit/group/1/ page.

    How can I do that? Thanks a lot!

    PS. I asked ChatGPT and got this answer that throws a Fatal error:

    function sync_bp_wp_profile_fields($user_id) {
        if (!bp_is_active('xprofile')) {
            return;
        }
    
        // Get BuddyPress profile field IDs (replace with your actual field IDs)
        $bp_first_name_id = 1; // Example field ID for First Name
        $bp_last_name_id = 2;  // Example field ID for Last Name
        $bp_url_id = 3;        // Example field ID for URL
        $bp_description_id = 4;// Example field ID for Description
    
        // Fetch BuddyPress profile data
        $first_name = xprofile_get_field_data($bp_first_name_id, $user_id);
        $last_name = xprofile_get_field_data($bp_last_name_id, $user_id);
        $url = xprofile_get_field_data($bp_url_id, $user_id);
        $description = xprofile_get_field_data($bp_description_id, $user_id);
    
        // Update WordPress user data
        wp_update_user([
            'ID' => $user_id,
            'first_name' => $first_name,
            'last_name' => $last_name,
            'user_url' => $url,
            'description' => $description,
        ]);
    }
    
    // Hook to update WordPress user data when BuddyPress profile is updated
    add_action('xprofile_updated_profile', 'sync_bp_wp_profile_fields', 10, 1);
    
    function sync_wp_bp_profile_fields($user_id) {
        if (!bp_is_active('xprofile')) {
            return;
        }
    
        // Get BuddyPress profile field IDs (replace with your actual field IDs)
        $bp_first_name_id = 1; // Example field ID for First Name
        $bp_last_name_id = 2;  // Example field ID for Last Name
        $bp_url_id = 3;        // Example field ID for URL
        $bp_description_id = 4;// Example field ID for Description
    
        // Fetch WordPress user data
        $user_info = get_userdata($user_id);
        $first_name = $user_info->first_name;
        $last_name = $user_info->last_name;
        $url = $user_info->user_url;
        $description = $user_info->description;
    
        // Update BuddyPress profile data
        xprofile_set_field_data($bp_first_name_id, $user_id, $first_name);
        xprofile_set_field_data($bp_last_name_id, $user_id, $last_name);
        xprofile_set_field_data($bp_url_id, $user_id, $url);
        xprofile_set_field_data($bp_description_id, $user_id, $description);
    }
    
    // Hook to update BuddyPress profile data when WordPress user data is updated
    add_action('profile_update', 'sync_wp_bp_profile_fields', 10, 1);
    add_action('user_register', 'sync_wp_bp_profile_fields', 10, 1);
    
Viewing 1 replies (of 1 total)

  • lunarca
    Participant

    @lunarca

    This is one of those times when you spend X hours trying to solve a problem and 5 mins after posting it you find the solution 💥

    Just for the record, undet Types of fields there are “WordPress fields” and there you can choose Biography and URL.

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.
Skip to toolbar