WordPress Development Asked by marccaps on December 1, 2021
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.
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' );
Answered by Prafulla Kumar Sahu on December 1, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP