0

Is there a way or a plugin to make Buddypress user profile dynamic? For example there's a field called contact number. The user should be able to dynamically add multiple contact numbers by clicking "Add contact number" button.

Here's an example from wordpress.com enter image description here

Thank you.

  • You could do this by building your own custom field type which can handle storing & parsing multiple values. I don't know of a pre-built solution. See BP_XProfile_Field_Type for details. – user66711 Apr 6 '17 at 21:29
0

This will get your job done. or you may like to use BuddyPress Xprofile Custom Fields Type plugin.

//Adding a metabox in user extended profile page
function bp_user_meta_box() {

    add_meta_box(
        'metabox_id',
        __( 'Metabox Title', 'buddypress' ),
        'bp_user_inner_meta_box', // function that displays the contents of the meta box
        get_current_screen()->id
    );
}
add_action( 'bp_members_admin_user_metaboxes', 'bp_user_meta_box');
function bp_user_inner_meta_box() {
    echo '<p>This is where you write your form inputs for user settings. Or you can output information pertaining to this user. For example, the Achievements plugin could show the users badges here. </p>';
    $user_id = get_current_user_id();
    $facebook_name = get_user_meta( $user_id, 'facebook_name', true );
    $facebook_name = $facebook_name ?  $facebook_name : '';
    ?>    
    <label for="user_facebook_name">Facebook Name</label>
    <input type="text" name="facebook_name" id="user_facebook_name" value="<?php echo  $facebook_name; ?>" />
    <input type="submit" name="submit" value="Submit" />
    <?php
}

function bp_user_save_metabox() {

    if( isset( $_POST['submit'] ) ) {

        //$user_id = isset( $_GET['user_id'] ) ? $_GET['user_id'] : 0;
        $user_id = get_current_user_id();

        // you will need to use a $_POST param and validate before saving
        $meta_val = isset( $_POST['facebook_name'] ) ? sanitize_text_field( $_POST['facebook_name'] ) : '';

        // the $meta_val would be a $_POST param from inner meta box form
        update_user_meta( $user_id, 'facebook_name', $meta_val );
    }
}
add_action( 'bp_members_admin_update_user', 'bp_user_save_metabox' );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.