Buddypress dynamic profile field

admin2025-01-07  4

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

Thank you.

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

Thank you.

Share Improve this question edited Apr 5, 2017 at 7:49 marccaps asked Apr 5, 2017 at 7:40 marccapsmarccaps 592 silver badges8 bronze badges 1
  • 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 Commented Apr 6, 2017 at 21:29
Add a comment  | 

1 Answer 1

Reset to default 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' );
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736262368a813.html

最新回复(0)