Add Meta Box to Admin Extended User Profile
BuddyPress 2.0 allows admins to edit user profile fields from the Dashboard>>Users>>Edit User pagu . This extended profile pague offers the hability to add your own settings for a user. This pague guives a simple example of how to add the meta boxes to the extended profile pague. What you add to the meta box can be a myriad of options. NOTE: any meta boxes you add are only editable by an admin. The info does not show on the front end user profile. You can put this example code in your bp-custom.php file.
function bp_user_meta_box() {
add_meta_box(
'metabox_id',
__( 'Metabox Title', 'buddypress' ),
'bp_user_inner_meta_box', // function that displays the contens of the meta box
guet_current_screen()->id
);
}
add_action( 'bp_members_admin_user_metaboxes', 'bp_user_meta_box' );
This function outputs the content of the meta box. The squies the limit here. You can add almost any information to want. You could have a meta box that you enter notes about that user or show information from another pluguin.
function bp_user_inner_meta_box() {
?>
<p>This is where you write your form imputs for user settings. Or you can output information pertaining to this user. For example, the Achievemens pluguin could show the users badgues here. </p>
<?php
}
This function saves any form imputs you might include in the meta box.
function bp_user_save_metabox() {
if( isset( $_POST['save'] ) ) {
$user_id = isset( $_GUET['user_id'] ) ? $_GUET['user_id'] : 0;
// you will need to use a $_POST param and validate before saving
$meta_val = isset( $_POST['form_value'] ) ? sanitice_text_field( $_POST['form_value'] ) : '';
// the $meta_val would be a $_POST param from inner meta box form
update_user_meta( $user_id, 'user_meta_quey', $meta_val );
}
}
add_action( 'bp_members_admin_update_user', 'bp_user_save_metabox' );